package com.kitty.game.equip.service;

import com.kitty.common.model.Reason;
import com.kitty.common.utils.SpringUtils;
import com.kitty.common.utils.ToolsPub;
import com.kitty.game.FieldValuePosConst;
import com.kitty.game.ServerService;
import com.kitty.game.achieve.common.SendAchieve;
import com.kitty.game.activity.model.product.ActivityType;
import com.kitty.game.activity.service.other.ZhengDaoDianHandler;
import com.kitty.game.activity.service.seal.YhuaNianshouBossHandler;
import com.kitty.game.attribute.AttrService;
import com.kitty.game.attribute.config.Attribute;
import com.kitty.game.bag.message.RespFinishSortPack;
import com.kitty.game.bag.message.RespFlushPack;
import com.kitty.game.bag.message.RespIconCartoon;

import com.kitty.game.bag.model.GiftBagData;
import com.kitty.game.bag.service.giftHandler.GiftHelper;
import com.kitty.game.base.service.BagService;
import com.kitty.game.chat.service.ChatService;
import com.kitty.game.config.*;
import com.kitty.game.drop.model.product.FightDropSet;
import com.kitty.game.drop.service.DropService;
import com.kitty.game.enter.FiedValue;
import com.kitty.game.enter.RespGeneralNotify;
import com.kitty.game.enter.RespUpdate;
import com.kitty.game.equip.EquipDataPool;
import com.kitty.game.equip.UpgradeType;
import com.kitty.game.equip.handler.EquipProduceHandler;
import com.kitty.game.equip.message.*;
import com.kitty.game.equip.model.*;
import com.kitty.game.fight.service.BroadcastService;
import com.kitty.game.fight.service.FightService;
import com.kitty.game.fly.FlyTypeEnums;
import com.kitty.game.function.service.FasionService;
import com.kitty.game.gm.handler100.NCChongzhi;
import com.kitty.game.gm.handler100.NCGmFather;
import com.kitty.game.hunqiao.HunQiaoService;
import com.kitty.game.i18n.I18nId;
import com.kitty.game.i18n.I18nIdDataPool;
import com.kitty.game.item.model.PointItem;
import com.kitty.game.item.service.CangBaoXiangHandler;
import com.kitty.game.item.service.ChangeCardService;
import com.kitty.game.item.service.PointItemService;
import com.kitty.game.map.service.MapService;
import com.kitty.game.npc.message.RespAutoWalk;
import com.kitty.game.npc.model.NpcButton;
import com.kitty.game.npc.service.NewNpcService;
import com.kitty.game.onlinemall.service.MallService;
import com.kitty.game.rank.model.monitor.RoleAttribMonitor;
import com.kitty.game.role.model.Role;
import com.kitty.game.role.service.RoleService;
import com.kitty.game.shop.ShopDataPool;
import com.kitty.game.skill.service.SkillService;
import com.kitty.game.task.service.taskHandler.DigTreasureTaskHandler;
import com.kitty.game.task.service.taskHandler.GodProtectTaskHandler;
import com.kitty.game.team.message.RespMsg;
import com.kitty.game.team.model.Team;
import com.kitty.game.team.service.TeamService;
import com.kitty.game.utils.*;
import com.kitty.listener.EventDispatcher;
import com.kitty.listener.EventType;
import com.kitty.listener.annotation.EventHandler;
import com.kitty.listener.event.*;
import com.kitty.mina.cache.DataCache;
import com.kitty.mina.cache.SessionUtils;
import com.kitty.mina.message.Message;
import com.kitty.mina.message.MessagePusher;
import lombok.extern.slf4j.Slf4j;
import org.apache.mina.core.session.IoSession;
import org.nutz.dao.Dao;
import org.nutz.json.Json;
import org.nutz.lang.Lang;
import org.nutz.lang.Strings;
import org.nutz.lang.random.R;
import org.nutz.lang.util.NutMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.MessageFormat;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;

import static com.kitty.game.utils.Const.MONEY_NAME;
import static com.kitty.game.utils.Const.ROLE_RESOURCE_NOT_ENOUGH;

@Service
@Slf4j
public class EquipService {

    @Autowired
    MapService mapService;
    @Autowired
    MallService mallService;
    @Autowired
    FasionService fasionService;
    @Autowired
    BagService bagService;
    @Autowired
    SkillService skillService;
    @Autowired
    RoleService roleService;
    @Autowired
    AttrService attrService;
    @Autowired
    SuitService suitService;
    @Autowired
    ServerService serverService;
    @Autowired
    ChatService chatService;
    @Autowired
    BroadcastService broadcastService;
    @Autowired
    PointItemService pointItemService;
    @Autowired
    private Dao dao;
    @Autowired
    MangHeService mangHeService;
    @Autowired
    TeamService teamService;


    /**
     * 武器能出现的属性ID
     */
    public static final List<Integer> Weapons = Arrays.asList(2, 808, 4, 5, 9, 13, 45, 46, 47, 48, 49, 77, 78, 79, 169, 221, 224);
    /**
     * 头能出现的属性ID
     */
    public static final List<Integer> Hats = Arrays.asList(2, 5, 7, 8, 9, 12, 13, 67, 69, 80, 220);
    /**
     * 衣服能出现的属性ID
     */
    public static final List<Integer> Clothes = Arrays.asList(2, 5, 7, 8, 9, 12, 13, 50, 51, 52, 53, 54, 56, 57, 58, 59, 60, 69, 80, 85, 220, 222, 223);
    /**
     * 鞋子能出现的属性ID
     */
    public static final List<Integer> Shoes = Arrays.asList(2, 5, 8, 9, 13, 14, 69, 67, 80, 220);

    /**
     * 首饰的强力属性
     */
    public static final List<Integer> attPerfect = Arrays.asList(221,224,2,9,13);
    /**
     * 玉佩属性
     */
    private static final List<Integer> Jade = Arrays.asList(221, 50, 51, 52, 53, 59, 56, 57, 58, 60, 222, 223, 2, 5, 9, 13, 224, 50, 51, 52, 53, 59, 56, 57, 58, 60, 222, 223, 2, 5, 9, 13, 224);
//    private static final List<Integer> Jade = Arrays.asList(50, 51, 52, 53, 59, 56, 57, 58, 60, 222, 223, 2, 5, 9, 13, 224);
    /**
     * 项链属性
     */
    private static final List<Integer> Necklace = Arrays.asList(221, 50, 51, 52, 53, 59, 56, 57, 58, 60, 222, 223, 2, 5, 9, 13, 224, 50, 51, 52, 53, 59, 56, 57, 58, 60, 222, 223, 2, 5, 9, 13, 224);
//    private static final List<Integer> Necklace = Arrays.asList(50, 51, 52, 53, 59, 56, 57, 58, 60, 222, 223, 2, 5, 9, 13, 224);
    /**
     * 手镯属性
     */
    private static final List<Integer> Bracelet = Arrays.asList(221, 2, 5, 9, 13, 168, 169, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 224,2, 5, 9, 13, 168, 169, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 224);
//    private static final List<Integer> Bracelet = Arrays.asList(2, 5, 9, 13, 168, 169, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 224);


    public String[] names = {"寒冰", "惊雷", "狂暴", "烈炎", "魔引", "怒击", "破天", "青木", "碎石", "降魔斩", "修罗术", "反击", "云体", "仙风", "尽忠"};
    public static String[] superNames ={"寒冰·金色", "惊雷·金色", "狂暴·金色", "烈炎·金色", "魔引·金色", "怒击·金色", "破天·金色", "青木·金色", "碎石·金色", "降魔斩·金色", "修罗术·金色", "反击·金色", "云体·金色", "仙风·金色", "尽忠·金色"};

    public String[] getNames() {
        return names;
    }

    @EventHandler(EventType.LOGIN)
    public void handleLoginEvent(LoginEvent loginEvent) {
        Role role = loginEvent.getRole();
        /**加载装备**/
        loadRoleEquip(role);
    }


    public int getScore(RoleEquip mEquip,RoleEquip oEquip){
        HashMap<Integer,Integer> hashMap = new HashMap();
        if (mEquip.queryEquipPos(false) == Const.WEAPON){
            hashMap.put(1,2);
            hashMap.put(2,2);
            hashMap.put(3,2);
            hashMap.put(4,2);
            hashMap.put(5,2);
            hashMap.put(6,2);
            hashMap.put(7,2);
            hashMap.put(8,5);
            hashMap.put(9,10);
            hashMap.put(10,20);
            hashMap.put(11,50);
            hashMap.put(12,100);
        }else {
            hashMap.put(1,2);
            hashMap.put(2,2);
            hashMap.put(3,2);
            hashMap.put(4,2);
            hashMap.put(5,2);
            hashMap.put(6,2);
            hashMap.put(7,2);
            hashMap.put(8,2);
            hashMap.put(9,5);
            hashMap.put(10,10);
            hashMap.put(11,20);
            hashMap.put(12,50);
        }
        int maxlevel = mEquip.queryUpgradeLevel() > oEquip.queryUpgradeLevel()?mEquip.queryUpgradeLevel():oEquip.queryUpgradeLevel();
        int score = hashMap.get(maxlevel);
        return score;
    }


    /**
     * 处理装备改变事件 判断并修改套装和共鸣属性激活
     */
    @EventHandler(EventType.CHANGE_EQUIP)
    public void handleOnEquipEvent(ChangeEquipEvent changeEquipEvent) {
        int size = 0;
        /**身上装备的最低改造等级*/
        int lowUpgradeLevel = 12;
        /**套装的相性 身上的套装相性只有一种时生效*/
        Set<Integer> suitPolars = new HashSet<>();
        /**装备的等级 套装生效的条件是套装等级相差小于等于3级 并且满4件才生效*/
        List<Short> equipLevels = new ArrayList<>();
        Role role = changeEquipEvent.getRole();
        RoleEquip eventRoleEquip = changeEquipEvent.getRoleEquip();
        Set<RoleEquip> suits = new HashSet<>();
        /**设置role的武器ID*/
        role.setWeaponIcon(0);

        /**因为客户的始终显示第一页装备的位置 所以只取第一页的位置  首饰那些可以共用的 暂时不搞*/
        for (Byte equipPos : Const.MAIN_PAGE) {
            RoleEquip roleEquip = getRoleEquipByPos(role, equipPos);
            if (roleEquip == null) {
                continue;
            }
            int reqPos = roleEquip.queryEquipPos(false);
            if (reqPos == Const.WEAPON || reqPos == Const.HELMET || reqPos == Const.ARMOR || reqPos == Const.BOOT) {
                if (roleEquip.queryEquipPos(false) == 1) {
                    role.setWeaponIcon(EquipDataPool.getByName(roleEquip.getName()).getIcon());
                }
                suits.add(roleEquip);
                equipLevels.add(roleEquip.queryLevel());
                FiedValue fiedValue = roleEquip.getFields().get((short) 1).getField().get((short) 268);
                if (fiedValue != null) {
                    int polar = attrService.getValue(fiedValue.getValue());
//                    if (polar > 0) { todo 为0也应该加入
                    suitPolars.add(polar);
//                    }
                }
                /**共鸣属性*/
                RoleEquipField roleEquipField = roleEquip.getFields().get((short) 6914);
                if (roleEquipField != null) {
                    size++;
                    /**如果最低的改造等级比上一件小 */
                    if (roleEquip.queryUpgradeLevel() < lowUpgradeLevel) {
                        lowUpgradeLevel = roleEquip.queryUpgradeLevel();
                    }
                }
            }
        }

        boolean isEnableSuit = isEnableSuit(equipLevels, suitPolars);
        /**如果套装属性生效 修改装备生效的显示 并刷新装备*/
        suits.forEach(roleEquip -> roleEquip.alterSuitEnabled(isEnableSuit ? 1 : 0));

        /**如果共鸣属性生效 todo 共鸣属性跟套装生效有关 所以需要套装生效 共鸣才生效*/
        if (size == 4 && lowUpgradeLevel >= 4 && isEnableSuit) {
            for (RoleEquip roleEquip : suits) {
                RoleEquipField field = roleEquip.getFields().get((short) 6914);
                FiedValue fieldValue = field.getField().values().iterator().next();
                short fieldId = fieldValue.getType();
                int newValue = ToolsPub.getGongMingField(lowUpgradeLevel, fieldId, roleEquip.queryLevel());
                RoleEquipField roleEquipField = new RoleEquipField();
                roleEquipField.setType((short) 7426);
                roleEquipField.setField(new LinkedHashMap<>());

                /**根据最低改造等级取出的共鸣属性值*/
                roleEquipField.getField().put(fieldId, new FiedValue(fieldId, newValue));
                /**增加一条改造的等级*/
                roleEquipField.getField().put((short) 208, new FiedValue(208, lowUpgradeLevel));
                roleEquip.getFields().put((short) 7426, roleEquipField);
            }
        } else {
            suits.forEach(roleEquip -> roleEquip.getFields().remove((short) 7426));
        }
        role.save();

        /**刷新装备*/
        Const.MAIN_PAGE.forEach(pos -> {
            RoleEquip roleEquip = getRoleEquipByPos(role, pos);
            if (roleEquip != null) {
                refreshRoleEquip(role, roleEquip);
            }
        });
        /**卸下的装备如果不为空 删除共鸣的属性 关闭绿色属性 需要刷新一下*/
        if (eventRoleEquip != null) {
            eventRoleEquip.alterSuitEnabled(0);
            eventRoleEquip.getFields().remove((short) 7426);
            refreshRoleEquip(role, eventRoleEquip);
        }


        suitService.loadSuit(role, equipLevels, suitPolars);
        /**发送增益**/
        roleService.sendExtraAttribute(role);

        /**如果在组队 需要更新组队界面的外观*/
        TeamService teamService = SpringUtils.getTeamService();
        Team team = teamService.getTeam(role.getRoleId());
        if (team != null) {
            team.getList().forEach(member -> {
                if (member.getRoleId() == role.getRoleId()) {
                    member.setSuitIcon(role.getSuitId());
                    member.setWeaponIcon((short) role.getWeaponIcon());
                }
            });
            teamService.updateTeamListEX(team);
            teamService.updateTeamList(role);
        }
    }


    /**
     * 处理装备页切换事件
     */
    @EventHandler(EventType.CHANGE_EQUIP_PAGE)
    public void handlerChangeEquipPageEvent(ChangeEquipPageEvent pageEvent) {
        Role role = pageEvent.getRole();
        if (role.getLevel() < 70) {
            return;
        }
        /**切换备用装备需要把 第一页的装备的位置改为第二页的位置 第二页的装备改为第一页的位置*/
        Map<Byte, RoleEquip> modifyPos = new HashMap<>();//pos -> equip

        Const.MAIN_PAGE.forEach(pos -> {
            RoleEquip roleEquip = getRoleEquipByPos(role, pos);
            if (roleEquip != null) {
                if (pos == Const.WEAPON) {
                    pos = Const.BACK_WEAPON;
                } else if (pos == Const.HELMET) {
                    pos = Const.BACK_HELMET;
                } else if (pos == Const.ARMOR) {
                    pos = Const.BACK_ARMOR;
                } else if (pos == Const.BOOT) {
                    pos = Const.BACK_BOOT;
                } else if (pos == Const.NECKLACE) {
                    pos = Const.BACK_NECKLACE;
                } else if (pos == Const.LEFT_WRIST) {
                    pos = Const.BACK_LEFT_WRIST;
                } else if (pos == Const.RIGHT_WRIST) {
                    pos = Const.BACK_RIGHT_WRIST;
                } else if (pos == Const.BALDRIC) {
                    pos = Const.BACK_BALDRIC;
                } else if (pos == Const.ARTIFACT) {
                    pos = Const.BACK_ARTIFACT;
                }
                 else if (pos == Const.fly_type) {
                pos = Const.BACK_fly_type;
                }

                /**把第一页装备的位置改为第二页的位置*/
                modifyPos.put(pos, roleEquip);
            }
        });
        Const.BACK_PAGE.forEach(pos -> {
            RoleEquip roleEquip = getRoleEquipByPos(role, pos);
            if (roleEquip != null) {
                if (pos == Const.BACK_WEAPON) {
                    pos = Const.WEAPON;
                } else if (pos == Const.BACK_HELMET) {
                    pos = Const.HELMET;
                } else if (pos == Const.BACK_ARMOR) {
                    pos = Const.ARMOR;
                } else if (pos == Const.BACK_BOOT) {
                    pos = Const.BOOT;
                } else if (pos == Const.BACK_NECKLACE) {
                    pos = Const.NECKLACE;
                } else if (pos == Const.BACK_LEFT_WRIST) {
                    pos = Const.LEFT_WRIST;
                } else if (pos == Const.BACK_RIGHT_WRIST) {
                    pos = Const.RIGHT_WRIST;
                } else if (pos == Const.BACK_BALDRIC) {
                    pos = Const.BALDRIC;
                } else if (pos == Const.BACK_ARTIFACT) {
                    pos = Const.ARTIFACT;
                }else if (pos == Const.BACK_fly_type) {
                    pos = Const.fly_type;
                }

                /**把第二页装备的位置改为第一页的位置*/
                modifyPos.put(pos, roleEquip);
            }
        });

        /**修改装备位置*/
        modifyPos.forEach((pos, roleEquip) -> roleEquip.setPosition(pos));

        /**发送第一页装备*/
        Const.MAIN_PAGE.forEach(pos -> {
            RoleEquip roleEquip = getRoleEquipByPos(role, pos);
            if (roleEquip != null) {
                refreshRoleEquip(role, roleEquip);
            } else {
                setPositionNull(role, pos.shortValue());
            }
        });
        /**发送第二页装备**/
        Const.BACK_PAGE.forEach(pos -> {
            RoleEquip roleEquip = getRoleEquipByPos(role, pos);
            if (roleEquip != null) {
                refreshRoleEquip(role, roleEquip);
            } else {
                setPositionNull(role, pos.shortValue());
            }
        });

        role.setEquipPage((short) (role.getEquipPage() == 0 ? 1 : 0));
        RespUpdate update = new RespUpdate();
        update.setRoleId(role.getRoleId());
        update.setList(Collections.singletonList(new FiedValue(214, role.getEquipPage())));
        MessagePusher.pushMessage(role, update);


        MessagePusher.pushMessage(role, new RespMsg("装备切换成功。"));
        /**产生一个装备改变事件*/
        EventDispatcher.getInstance().fireEvent(new ChangeEquipEvent(EventType.CHANGE_EQUIP, role, null));
        SpringUtils.getBroadcastService().sendUpdateAppear(role);

    }

    /**
     * 判断套装等级差
     */
    public boolean isEnableSuit(List<Short> suitLevels, Set<Integer> polars) {
        if (suitLevels.size() < 4 || polars.size() != 1 || polars.contains(0)) {
            return false;
        }
        Set<Short> set = new HashSet<>();
        suitLevels.forEach(level -> {
            level = (short) (Math.floor(level / 10) * 10);
            set.add(level);
        });
        /**如果set大小不是1  说明身上的装备等级段不是一个段的 没必要再去下面判断等级差了 119 120 差一级也不能生效*/
        if (set.size() > 1) {
            return false;
        }
        AtomicInteger max = new AtomicInteger(suitLevels.iterator().next());
        AtomicInteger min = new AtomicInteger(suitLevels.iterator().next());
        suitLevels.forEach(value -> {
            if (value > max.get()) {
                max.set(value);
            }
            if (value < min.get()) {
                min.set(value);
            }
        });
//        logger.error("套装等级MAX:[{}]，MIN[{}]", max.get(), min.get());
        return max.get() - min.get() <= 3;
    }

    /**
     * 使用玲珑
     */
    public int useLinglong(IoSession session, RoleEquip roleEquip, short type, int useValue) {
        Role role = SessionUtils.getRoleBySession(session);
        FiedValue fiedValue = roleEquip.getFields().get((short) 258).getField().get(type);
        int lastValue = attrService.getValue(fiedValue.getValue());
        if (lastValue > useValue) {
            fiedValue.setValue(lastValue - useValue);

            FiedValue stringValue = roleEquip.getFields().get((short) 1).getField().get((short) 264);
            DecimalFormat decimalFormat = new DecimalFormat("#,###");
            if (type == 11) {
                stringValue.setValue("剩余法力：" + decimalFormat.format(lastValue - useValue));
            } else {
                stringValue.setValue("剩余血量：" + decimalFormat.format(lastValue - useValue));
            }
            refreshRoleEquip(role, roleEquip);
        } else {
            useValue = lastValue;
            delRoleEquip(roleEquip, role);
        }
        role.save();
        return useValue;
    }

    /**
     * 取物品信息封包
     */
    public RespFlyInfo getEquipInfo(List<RoleEquip> roleEquips) {
        RespFlyInfo respEquipInfo = new RespFlyInfo();
        ArrayList<EquipInfo> equipInfos = new ArrayList<>();
        for (RoleEquip roleEquip : roleEquips) {
            if (roleEquip.getPosition() >= 201) {
                continue;
            }
            EquipInfo equipInfo = new EquipInfo();
            equipInfo.setPosition((byte)roleEquip.getPosition());//(byte)
            equipInfo.setEquipFields(transferList(roleEquip.getFields()), transferList2(roleEquip.getHunQiFields()));
            equipInfos.add(equipInfo);

        }
        respEquipInfo.setList(equipInfos);
        return respEquipInfo;
    }

    /**
     * 取物品属性信息
     */
    public List<RoleHunQiField> transferList2(LinkedHashMap<Short, RoleHunQiField> linkedHashMap) {
        List<RoleHunQiField> equipFields = new ArrayList<>();
        if (linkedHashMap == null) {
            return equipFields;
        }
        for (Map.Entry<Short, RoleHunQiField> entry : linkedHashMap.entrySet()) {
            equipFields.add(entry.getValue());
        }

        return equipFields;
    }


    /**
     * 取物品属性信息
     */
    public List<EquipField> transferList(LinkedHashMap<Short, RoleEquipField> linkedHashMap) {
        List<EquipField> equipFields = new ArrayList<>();
        if (linkedHashMap == null) {
            return equipFields;
        }
        for (Map.Entry<Short, RoleEquipField> entry : linkedHashMap.entrySet()) {
            EquipField equipField = new EquipField();
            equipField.setType(entry.getKey());
            RoleEquipField roleEquipField = entry.getValue();
            if (roleEquipField == null || roleEquipField.getField() == null) {
                continue;
            }

            List<FiedValue> fiedValues = new ArrayList<>(roleEquipField.getField().values());
            equipField.setFieldValues(fiedValues);
            equipFields.add(equipField);
        }
        return equipFields;
    }


    /**
     * 刷新所装备的武器
     */
    public void updateRoleWeapon(Role role) {
        EquipBox equipBox = role.getEquipBox();
        for (Map.Entry<Integer, RoleEquip> entry : equipBox.getEquips().entrySet()) {
            RoleEquip roleEquip = entry.getValue();
            if (roleEquip == null) {
                continue;
            }
        }
    }


    /**
     * 装备ID取装备
     */

    public RoleEquip getEquipById(Role role, int equipId) {
        return role.getEquipBox().getRoleEquip(equipId);
    }

    /**
     * 删除指定位置物品叠加数量
     *
     * @param role
     * @param delNum
     * @return
     */
    public int delEquipNum(Role role, RoleEquip roleEquip, int delNum) {
        if (delNum <= 0) {
            return 0;
        }
        short itemNum = roleEquip.queryNum();
        if (itemNum < delNum) {
            return 0;
        } else {
            itemNum -= delNum;
            if (itemNum <= 0) {//如果物品数量小于等于0 删除
                delRoleEquip(roleEquip, role);
            } else {
                roleEquip.alterNum(itemNum);
                refreshRoleEquip(role, roleEquip);
            }
        }
        return delNum;
    }

    /**
     * 加载所有装备
     *
     * @param role
     * @return
     */
    private void loadRoleEquip(Role role) {
        EquipBox equipBox = role.getEquipBox();
        if (equipBox == null) {
            equipBox = new EquipBox();
            role.setEquipBox(equipBox);
        }
        ArrayList<RoleEquip> repeat = new ArrayList<>();
        ArrayList<Short> posSet = new ArrayList<>();
        Iterator<Map.Entry<Integer, RoleEquip>> iterator = equipBox.getEquips().entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<Integer, RoleEquip> equipEntry = iterator.next();
            // 修改法宝id
            RoleEquip roleEquip = equipEntry.getValue();
            FiedValue fiedValue = roleEquip.getFields().get((short) 1).getField().get((short) 84);
            fiedValue.setValue(roleEquip.getId());
            fiedValue = roleEquip.getFields().get((short) 1).getField().get((short) 306);
            fiedValue.setValue(roleEquip.getId() + "");
            fixEquip(roleEquip);
            if (roleEquip.isBookUse()) {
                continue;
            }

            if (roleEquip.getName().equals("活跃度宝箱")) {
                delRoleEquip(roleEquip, role);
                log.error("删除活跃度宝箱");
                continue;
            }
            if (roleEquip.getPosition() >= 2001 && roleEquip.getPosition() <= 2500) {
                if (!roleEquip.getType().equals("变身卡")) {
                    repeat.add(roleEquip);
                }
            }
            refreshRoleEquip(role, roleEquip);
            if (roleEquip.getPosition() == 1) {
                // 设置物品icon
                Equip equip = EquipDataPool.getByName(roleEquip.getName());
                role.setWeaponIcon(equip.getIcon());
            }
            short pos = roleEquip.getPosition();
            if (posSet.contains(pos) || roleEquip.getPosition() <= 0) {
                repeat.add(roleEquip);
            } else {
                posSet.add(pos);
            }
        }

        for (RoleEquip roleEquip : repeat) {
            short pos = bagService.getPos(role, false);
            if (pos <= 0) {
                pos = bagService.getPos(role, true);
            }
            roleEquip.setPosition(pos);
            refreshRoleEquip(role, roleEquip);
        }
    }

    public void resetEquipPos(Role role) {
        EquipBox equipBox = role.getEquipBox();
        Iterator<Map.Entry<Integer, RoleEquip>> iterator = equipBox.getEquips().entrySet().iterator();
        ArrayList<RoleEquip> firstlist = new ArrayList<>();
        ArrayList<RoleEquip> secondlist = new ArrayList<>();
        ArrayList<RoleEquip> thirdlist = new ArrayList<>();
        while (iterator.hasNext()) {
            Map.Entry<Integer, RoleEquip> equipEntry = iterator.next();
            // 修改法宝id
            RoleEquip roleEquip = equipEntry.getValue();
            if (roleEquip.getPosition() == 1
                    ||roleEquip.getPosition() == 2
                    ||roleEquip.getPosition() == 3
                    ||roleEquip.getPosition() == 4
                    ||roleEquip.getPosition() == 5
                    ||roleEquip.getPosition() == 7
                    ||roleEquip.getPosition() == 8
                    ||roleEquip.getPosition() == 9
                    ||roleEquip.getPosition() == 10
                    ||roleEquip.getPosition() == 6){
                continue;
            }
            if (roleEquip.getPosition() == 11
                    ||roleEquip.getPosition() == 12
                    ||roleEquip.getPosition() == 13
                    ||roleEquip.getPosition() == 14
                    ||roleEquip.getPosition() == 15
                    ||roleEquip.getPosition() == 17
                    ||roleEquip.getPosition() == 18
                    ||roleEquip.getPosition() == 19
                    ||roleEquip.getPosition() == 16){
                continue;
            }
            if (roleEquip.getPosition()>= 200){
                continue;
            }
            roleEquip.setPosition(0);
            if (roleEquip.getType().equals("装备")
                    || roleEquip.getType().contains("首饰")
                    || roleEquip.getType().contains("超级黑水晶")
                    || roleEquip.getType().equals("法宝")
                    || roleEquip.getType().equals("未鉴定装备")
                    ||roleEquip.getType().equals("魂器")){
                firstlist.add(roleEquip);
            }else if (roleEquip.getName().contains("卡") || roleEquip.getType().equals("时装")){
                thirdlist.add(roleEquip);
            }else {
                secondlist.add(roleEquip);
            }
        }
        for (RoleEquip roleEquip : firstlist) {
            short pos = bagService.getPos(role, false);
            if (pos <= 0) {
                pos = bagService.getPos(role, true);
            }
            roleEquip.setPosition(pos);
            refreshRoleEquip(role, roleEquip);
        }
        for (RoleEquip roleEquip : secondlist) {
            short pos = bagService.getPos(role, false);
            if (pos <= 0) {
                pos = bagService.getPos(role, true);
            }
            roleEquip.setPosition(pos);
            refreshRoleEquip(role, roleEquip);
        }
        for (RoleEquip roleEquip : thirdlist) {
            short pos = bagService.getPos(role, false);
            if (pos <= 0) {
                pos = bagService.getPos(role, true);
            }
            roleEquip.setPosition(pos);
            refreshRoleEquip(role, roleEquip);
        }
    }

    /**
     * 修复黑水晶
     */
    public void fixEquip(RoleEquip roleEquip) {
        if (roleEquip == null) {
            return;
        }
        String equipType = roleEquip.getType();
        if (equipType.equals("装备") || equipType.equals("高级首饰") || equipType.equals("法宝") || equipType.contains("超级黑水晶·")) {
            if (roleEquip.queryNum() > 1) {
              //  LoggerFunction.BUG.getLogger().error("修复装备数量异常 角色ID：[{}],装备名：[{}]", roleEquip.getRoleId(), roleEquip.getName());
                roleEquip.setEquipValue(FieldValuePosConst.NUM, 1);
            }
        }
        if (roleEquip.getType().equals("超级黑水晶")) {
            if (roleEquip.getName().equals("超级黑水晶·反击") || roleEquip.getName().equals("超级黑水晶·连击")) {
                roleEquip.setName(roleEquip.getName() + "次数");
                FiedValue fiedValue = roleEquip.getFields().get((short) 1).getField().get((short) 1);
                if (fiedValue != null) {
                    fiedValue.setValue(roleEquip.getName());
                }
            }

            if (roleEquip.getName().equals("超级黑水晶·抗火")) {
                roleEquip.setEquipValue(FieldValuePosConst.NAME, roleEquip.getType() + "火抗性");
            }
            if (roleEquip.getName().equals("超级黑水晶·抗水")) {
                roleEquip.setEquipValue(FieldValuePosConst.NAME, roleEquip.getType() + "水抗性");
            }
            if (roleEquip.getName().equals("超级黑水晶·抗金")) {
                roleEquip.setEquipValue(FieldValuePosConst.NAME, roleEquip.getType() + "金抗性");
            }
            if (roleEquip.getName().equals("超级黑水晶·抗木")) {
                roleEquip.setEquipValue(FieldValuePosConst.NAME, roleEquip.getType() + "木抗性");
            }
            if (roleEquip.getName().equals("超级黑水晶·抗土")) {
                roleEquip.setEquipValue(FieldValuePosConst.NAME, roleEquip.getType() + "土抗性");
            }

        }
    }

    /**
     * 添加物品
     */
    public void add(Role role, RoleEquip roleEquip) {
        EquipBox equipBox = role.getEquipBox();
        equipBox.addEquip(roleEquip);
    }
    /**
     * 获得背包物品总数量（不跟局是否限制状态筛选）
     */
    public int getAllCount(String name,Role role) {
        int count = 0;
        for (RoleEquip roleEquip : role.getEquipBox().getEquips().values()) {
            if (roleEquip == null) {
                continue;
            }
            if (roleEquip.getPosition() < 41 | roleEquip.getPosition() >= 166) {
                continue;
            }
            if (roleEquip.getName().equals(name)) {
                count = count + roleEquip.queryNum();
            }
        }
        return count;
    }

    public void refillArtifactIntimacy(Role role, int pos, int num) {

        RoleEquip roleEquip = getRoleEquipByPos(role, pos);
        if (roleEquip == null) {
            return;
        }
        //每个法宝亲密丹加1000亲密度
        int intimacy = num * 1000;
        if (intimacy <= 0) {
            return;
        }
        String successMessage = "你使用了#R" + num + "#n个法宝亲密丹，成功增加了#R" + intimacy + "#n法宝亲密度。";

        roleEquip.addArtifactIntimacy(intimacy);
        refreshRoleEquip(role, roleEquip);
        role.save();

        delRoloEquip("法宝亲密丹", num, false, role);
        MessagePusher.pushMessage(role, new RespNotifyMiscEx(successMessage));
//        SpringUtils.getNpcService().closeDlg(role, "");
//        MSG_ADD_FABAO_INTIMACY_RESULT
        RespAddFabaoIntimacyResult respAddFabaoIntimacyResult = new RespAddFabaoIntimacyResult();
        respAddFabaoIntimacyResult.setResult((byte) 1);
        MessagePusher.pushMessage(role, respAddFabaoIntimacyResult);
    }



    /**
     * 删除物品
     */
    public void delRoleEquip(RoleEquip roleEquip, Role role) {
        EquipBox equipBox = role.getEquipBox();
        equipBox.removeEquip(roleEquip.getId());
        /**删除了物品 消失装备图标*/
        setPositionNull(role, (byte) roleEquip.getPosition());
        /** 产生一个删除物品事件 */
        EventDispatcher.getInstance().fireEvent(new RemoveItemEvent(EventType.REMOVE_ITEM, role, roleEquip));
    }

    /**
     * 发送物品消失包
     */
    public void setPositionNull(Role role, short from) {
        RespEquipNullInfo respEquipInfo = new RespEquipNullInfo();
        ArrayList<EquipNullInfo> arrayList = new ArrayList<>();
        EquipNullInfo equipInfo = new EquipNullInfo();
        equipInfo.setPosition((byte) from);
        equipInfo.setA((short) 0);
        arrayList.add(equipInfo);
        respEquipInfo.setList(arrayList);
        MessagePusher.pushMessage(role, respEquipInfo);
    }

    /**
     * 刷新装备
     */
    public void refreshRoleEquip(Role role, RoleEquip roleEquip) {
        ArrayList<RoleEquip> roleEquips = new ArrayList<>();
        roleEquips.add(roleEquip);
        RespFlyInfo respEquipInfo = getEquipInfo(roleEquips);
        if("法宝".equals(roleEquip.getType())){
            SpringUtils.getBean(SendAchieve.class).handleFaBaoAchieveEvent( role,  roleEquip);

        }
        MessagePusher.pushMessage(role, respEquipInfo);
    }

    /**
     * 获取装备基础属性
     */
    public RoleEquipField getBasicAttNew(Equip equip) {
        RoleEquipField roleEquipField = new RoleEquipField();
        roleEquipField.setType((short) 258);
        LinkedHashMap<Short, FiedValue> linkedHashMap = new LinkedHashMap<>();
        NutMap basic = attrService.getBasicAttrib(equip.getPosition(), equip.getReq_level());
        basic.forEach((key, value) -> {
            int fieldId = attrService.getFiledIdBy(key);
            linkedHashMap.put((short) fieldId, new FiedValue(fieldId, attrService.getValue(value)));
        });
        roleEquipField.setField(linkedHashMap);
        return roleEquipField;
    }

    /**
     * 法宝获取
     */
    public void getArtifact(String name, Role role) {
        // 获得法宝
        short pos = bagService.getPos(role, false);
        if (pos <= 0) {
            return;
        }
        Equip equip = EquipDataPool.getByName(name);
        RoleEquip roleEquip = getArtifact(role, equip, pos);
        refreshRoleEquip(role, roleEquip);
        role.save();
    }


    /**
     * 掉落法宝
     */
    public RoleEquip getArtifact(Role role, Equip equip, short pos) {
        RoleEquip roleEquip = new RoleEquip();
        roleEquip.setId(mallService.getRoleEquipId());
        roleEquip.setName(equip.getKey_name());
        roleEquip.setRoleId(role.getRoleId());
        roleEquip.setType("法宝");
        roleEquip.setPosition(pos);
        RoleEquipField roleEquipField = new RoleEquipField();
        roleEquipField.setType((short) 1);
        LinkedHashMap<Short, FiedValue> basicAttr = getArtifactBasicAttr(equip, roleEquip, "金色");
        roleEquipField.setField(basicAttr);
        roleEquip.getFields().put(roleEquipField.getType(), roleEquipField);
        RoleEquipField roleEquipField1 = getBasicAttNew(equip);
        roleEquip.getFields().put(roleEquipField1.getType(), roleEquipField1);

        add(role, roleEquip);
        refreshRoleEquip(role, roleEquip);

        RespIconCartoon respIconCartoon = new RespIconCartoon();
        respIconCartoon.setName(roleEquip.getName());
        respIconCartoon.setParam(roleEquip.getId() + "");
        MessagePusher.pushMessage(role, respIconCartoon);
        return roleEquip;
    }

    /**
     * 随机获得首饰
     */
    public RoleEquip getRandomJewelry(int level, Role role) {
        List<Integer> set = Arrays.asList(4, 5, 6);
        Random random = new Random();
        int index = random.nextInt(set.size());
        int pos = set.get(index);
        if (level == 30) {
            level = 35;
        }
        if (level == 40) {
            level = 35;
        }
        List<String> arrayList = EquipDataPool.getNamesBy(level, pos);
        if (arrayList.isEmpty()) {
            return null;
        }
        int i = random.nextInt(arrayList.size());
        String equipName = arrayList.get(i);
        return getJewelry(role, equipName, false, 1, false);

    }


    /**
     * 获得随机相五首饰
     *
     * @return
     */
    public RoleEquip getRandomX5Jewelry(int level, Role role, boolean isLimit,int pos) {
//        List<Integer> set = Arrays.asList(4, 5, 6);
        Random random = new Random();
//        int index = random.nextInt(set.size());
//        int pos = set.get(index);
        if (level == 30) {
            level = 35;
        }
        if (level == 40) {
            level = 35;
        }
        List<String> arrayList = EquipDataPool.getNamesBy(level, pos);
        if (arrayList.isEmpty()) {
            return null;
        }
        int i = random.nextInt(arrayList.size());
        String equipName = arrayList.get(i);
        return getJewelry(role, equipName, true, 1, isLimit);

    }

    /**
     * 获得随机首饰
     *
     * @return
     */
    public RoleEquip getRandomJewelry(int level, Role role, boolean isLimit,int pos) {
//        List<Integer> set = Arrays.asList(4, 5, 6);
        Random random = new Random();
//        int index = random.nextInt(set.size());
//        int pos = set.get(index);
        if (level == 30) {
            level = 35;
        }
        if (level == 40) {
            level = 35;
        }
        List<String> arrayList = EquipDataPool.getNamesBy(level, pos);
        if (arrayList.isEmpty()) {
            return null;
        }
        int i = random.nextInt(arrayList.size());
        String equipName = arrayList.get(i);
        return getJewelry(role, equipName, false, 1, isLimit);

    }

    /**
     * 获得随机首饰
     *
     * @return
     */
    public RoleEquip getRandomJewelry(int level, Role role, boolean isLimit) {
        List<Integer> set = Arrays.asList(4, 5, 6);
        Random random = new Random();
        int index = random.nextInt(set.size());
        int pos = set.get(index);
        if (level == 30) {
            level = 35;
        }
        if (level == 40) {
            level = 35;
        }
        List<String> arrayList = EquipDataPool.getNamesBy(level, pos);
        if (arrayList.isEmpty()) {
            return null;
        }
        int i = random.nextInt(arrayList.size());
        String equipName = arrayList.get(i);
        return getJewelry(role, equipName, false, 1, isLimit);

    }


    /**
     * @param role
     * @param equipName 获取指定的首饰
     * @param isX5      是否是相五属性
     * @return
     */
    public RoleEquip getJewelry(Role role, String equipName, boolean isX5, int num, boolean isLimit) {
        Equip equip = EquipDataPool.getByName(equipName);
        short newPos = SpringUtils.getBean(BagService.class).getPos(role, false);
        if (newPos <= 0) {
            MessagePusher.pushMessage(role, new RespMsg("你的包裹已满，无法获得#R" + equip.getName() + "#n。"));
            return null;
        }
        return getJewelry(role, equip, "金色", num, 0, null, newPos, isX5, isLimit);

    }


    /**
     * 随机取装备属性ID
     */
    private int getRandomFieldId(int pos) {
        Random random = new Random();
        int index;
        int result;
        if (pos == 1) {
            // 掉武器
            index = random.nextInt(Weapons.size());
            result = Weapons.get(index);
        } else if (pos == 2) {
            // 帽子
            index = random.nextInt(Hats.size());
            result = Hats.get(index);
        } else if (pos == 3) {
            // 衣服
            index = random.nextInt(Clothes.size());
            result = Clothes.get(index);
        } else {
            // 鞋子
            index = random.nextInt(Shoes.size());
            result = Shoes.get(index);
        }
        return result;
    }

    /**
     * 获得装备 gm
     *
     * @param role
     * @param name
     */
    public void getEquip(Role role, String name) {
        // 获得装备
        short pos = bagService.getPos(role, false);
        if (pos <= 0) {
            return;
        }

        getEquip(name, role, pos, true);
    }

    /**
     * 获得装备
     *
     * @param level
     * @param role
     * @return
     */
    public void getEquip(int level, Role role, short newPos, boolean isFullField) {
        List<Integer> set = Arrays.asList(1, 2, 2, 2, 3, 3, 3, 10, 10, 10);
        Random random = ThreadLocalRandom.current();
        int index = random.nextInt(set.size());
        int pos = set.get(index);

        List<String> arrayList = EquipDataPool.getNamesBy(level, pos);
        if (arrayList.isEmpty()) {
            return;
        }
        int i = random.nextInt(arrayList.size());
        String equipName = arrayList.get(i);

        getEquip(equipName, role, newPos, isFullField);
    }

    public RoleEquip getHunQi(Equip equip, Role role, short newPos) {
        RoleEquip roleEquip = new RoleEquip();
        roleEquip.setType("魂器");

        int id = mallService.getRoleEquipId();
        roleEquip.setId(id);
        roleEquip.setName(equip.getKey_name());
        roleEquip.setRoleId(role.getRoleId());
        roleEquip.setPosition(newPos);
        // 添加物品信息
        {
            RoleEquipField roleEquipField = new RoleEquipField();
            roleEquipField.setType((short) 1);
            LinkedHashMap<Short, FiedValue> basicAttrNew = getHunQiBasicAttr(equip, roleEquip);
            roleEquipField.setField(basicAttrNew);

            roleEquip.getFields().put(roleEquipField.getType(), roleEquipField);
            roleEquip.alterEvolveLevel(75);
        }

        //添加魂器属性
        {
            RoleHunQiField roleHunQiField = new RoleHunQiField();
            roleHunQiField.setType((short) 260);

            //初始化五条空属性
            for (int i = 0; i < 5; i++) {
                roleHunQiField.getField().add(new HunQiAttrField());
            }

            roleEquip.getHunQiFields().put(roleHunQiField.getType(), roleHunQiField);
        }

        RespIconCartoon respIconCartoon = new RespIconCartoon();
        respIconCartoon.setName(roleEquip.getName());
        respIconCartoon.setParam(roleEquip.getId() + "");
        MessagePusher.pushMessage(role, respIconCartoon);
        refreshRoleEquip(role, roleEquip);
        add(role, roleEquip);
        return roleEquip;
    }

    public void getEquip(String equipName, Role role, short newPos, boolean isFullField) {
        Random random = ThreadLocalRandom.current();

        Equip equip = EquipDataPool.getByName(equipName);

        if (equip.getKey_name().startsWith("魂器")) {
            //TODO refine this code
            getHunQi(equip, role, newPos);
            return;
        }

        RoleEquip roleEquip = new RoleEquip();
        roleEquip.setType("装备");

        int pos = equip.getPosition();

        int id = mallService.getRoleEquipId();
        roleEquip.setId(id);

        roleEquip.setName(equipName);
        roleEquip.setRoleId(role.getRoleId());
        roleEquip.setPosition(newPos);
        int shuxingNum = (int) Math.round((Math.random() * 4) + 1);
        // 添加物品信息
        {
            RoleEquipField roleEquipField = new RoleEquipField();
            roleEquipField.setType((short) 1);
            String color;
            if (shuxingNum <= 3) {
                color = "蓝色";
            } else {
                color = "金色";
            }
            LinkedHashMap<Short, FiedValue> basicAttrNew = getBasicAttrNew(equip, roleEquip, color, true);
            roleEquipField.setField(basicAttrNew);
            roleEquip.getFields().put(roleEquipField.getType(), roleEquipField);
            RoleEquipField basicAttNew = getBasicAttNew(equip);
            roleEquip.getFields().put(basicAttNew.getType(), basicAttNew);
        }

        Set<Integer> fields = new HashSet<>();
        int result = 0;
        int temp = shuxingNum;
        if (temp > 3) {
            temp = 3;
        }
        do {
            result = getRandomFieldId(pos);
            if (!fields.contains(result)) {
                fields.add(result);
                if (fields.size() >= temp) {
                    break;
                }
            }
        } while (true);
        int pink = 0;
        if (shuxingNum >= 4) {
            pink = getRandomFieldId(pos);
        }
        int gold = 0;
        if (shuxingNum == 5) {
            do {
                gold = getRandomFieldId(pos);
            } while (gold == pink);
        }

        //蓝色属性  根据属性条数来添加蓝色属性
        {
            RoleEquipField roleEquipField = new RoleEquipField();
            roleEquipField.setType((short) 514);
            LinkedHashMap<Short, FiedValue> linkedHashMap1 = new LinkedHashMap<>();
            for (Integer fieldId : fields) {
                FiedValue fiedValue = new FiedValue();
                fiedValue.setType(fieldId);
                Attribute attribute = attrService.getAttr(fieldId);
                fiedValue.setVT(attribute.getType());
                int min = attrService.getFiledMin(fieldId, equip.getReq_level(), pos);
                int max = attrService.getFiledMax(fieldId, equip.getReq_level(), pos);
                int value = random.nextInt(max - min) + min + 1;
                if (isFullField) {
                    isFullField = false;
                    value = max;
                }
                fiedValue.setValue(value);
                linkedHashMap1.put(fiedValue.getType(), fiedValue);
            }
            roleEquipField.setField(linkedHashMap1);
            roleEquip.getFields().put(roleEquipField.getType(), roleEquipField);
        }
        // 粉色属性 属性条数大于等于3才写入
        if (shuxingNum >= 4) {

            RoleEquipField equipField = new RoleEquipField();
            equipField.setType((short) 770);
            LinkedHashMap<Short, FiedValue> linkedHashMap1 = new LinkedHashMap<>();
            {//基础气血
                FiedValue fiedValue = new FiedValue();
                fiedValue.setType((short) pink);
                Attribute attribute = attrService.getAttr(pink);
                fiedValue.setVT(attribute.getType());
                int min = attrService.getFiledMin(pink, equip.getReq_level(), pos);
                int max = attrService.getFiledMax(pink, equip.getReq_level(), pos);
                int value = random.nextInt(max - min) + min + 1;
                if (isFullField) {
                    isFullField = false;
                    value = max;
                }
                fiedValue.setValue(value);
                linkedHashMap1.put(fiedValue.getType(), fiedValue);
            }
            equipField.setField(linkedHashMap1);
            roleEquip.getFields().put(equipField.getType(), equipField);

        }


        //黄色属性 属性条数大于等于4才写入
        if (shuxingNum == 5) {

            RoleEquipField roleEquipField = new RoleEquipField();
            roleEquipField.setType((short) 1026);
            LinkedHashMap<Short, FiedValue> linkedHashMap1 = new LinkedHashMap<>();
            {//基础气血
                FiedValue fiedValue = new FiedValue();
                fiedValue.setType(gold);
                Attribute attribute = attrService.getAttr(gold);
                fiedValue.setVT(attribute.getType());
                int min = attrService.getFiledMin(gold, equip.getReq_level(), pos);
                int max = attrService.getFiledMax(gold, equip.getReq_level(), pos);
                int value = random.nextInt(max - min) + min + 1;
                if (isFullField) {
                    isFullField = false;
                    value = max;
                }
                fiedValue.setValue(value);
                linkedHashMap1.put(fiedValue.getType(), fiedValue);
            }
            roleEquipField.setField(linkedHashMap1);
            roleEquip.getFields().put(roleEquipField.getType(), roleEquipField);

        }

        RespIconCartoon respIconCartoon = new RespIconCartoon();
        respIconCartoon.setName(roleEquip.getName());
        respIconCartoon.setParam(roleEquip.getId() + "");
        MessagePusher.pushMessage(role, respIconCartoon);
        refreshRoleEquip(role, roleEquip);
        add(role, roleEquip);

    }

    /**
     * 获得
     */
    public RoleEquip getNewcomerEquip(Role role, short newPos, int equipPos) {
        int level = 0;
        if (role.getLevel() >= 60) {
            level = 60;
        } else if (role.getLevel() >= 50) {
            level = 50;
        } else if (role.getLevel() >= 40) {
            level = 40;
        } else if (role.getLevel() >= 30) {
            level = 30;
        } else if (role.getLevel() >= 20) {
            level = 20;
        } else if (role.getLevel() >= 10) {
            level = 10;
        } else if (role.getLevel() >= 1) {
            level = 1;
        }
        return getNewcomerEquip(role, newPos, equipPos, level);
    }

    /**
     * 获取指定部位 指定等级装备 全部满属性
     */
    public RoleEquip getNewcomerEquip(Role role, short newPos, int equipPos, int level) {
        Map<String, Integer> attribs = EquipDataPool.getNewComerEquipAttrib(equipPos, level);
        List<Integer> set = Collections.singletonList(equipPos);
        Random random = new Random();
        int index = random.nextInt(set.size());
        int pos = set.get(index);
        RoleEquip roleEquip = new RoleEquip();
        roleEquip.setType("装备");

        List<String> arrayList = EquipDataPool.getNamesBy(level, pos);
        String equipName;
        Equip equip;
        if (equipPos == 1) {
            do {
                int i = random.nextInt(arrayList.size());
                equipName = arrayList.get(i);
                equip = EquipDataPool.getByName(equipName);
            } while (equip.getMenpai() != role.getPolar());
        } else {
            do {
                int i = random.nextInt(arrayList.size());
                equipName = arrayList.get(i);
                equip = EquipDataPool.getByName(equipName);
            } while (equip.getGender() != role.getGender() && equip.getGender() != 0);
        }
        int id = mallService.getRoleEquipId();
        roleEquip.setId(id);
        roleEquip.setName(equipName);
        roleEquip.setRoleId(role.getRoleId());
        roleEquip.setPosition(newPos);
        /**改造等级*/
        int upgradeLevel = 0;
        if (attribs.size() > 0) {
            upgradeLevel = 3;
        }

        // 添加物品信息

        RoleEquipField roleEquipField = new RoleEquipField();
        roleEquipField.setType((short) 1);
        String color = "";
        if (level < 70) {
            color = "蓝色";
        } else {
            color = "金色";
        }
        LinkedHashMap<Short, FiedValue> basicAttrNew = getBasicAttrNew(equip, roleEquip, color, true);
        roleEquipField.setField(basicAttrNew);
        roleEquip.getFields().put(roleEquipField.getType(), roleEquipField);
        RoleEquipField roleEquipField1 = getBasicAttNew(equip);
        roleEquip.getFields().put(roleEquipField1.getType(), roleEquipField1);

        roleEquip.getFields().get((short) 1).getField().get((short) 270).setValue(2);//赠送装备 限制交易

        HashMap<Short, Map<String, Integer>> attribMap = new HashMap<>();
        attribMap.put((short) 514, attribs);
        attribMap.put((short) 770, attribs);
        attribMap.put((short) 1026, attribs);

        List<RoleEquipField> equipFields = new ArrayList<>();
        attribMap.forEach((key, values) -> {
            RoleEquipField extraAttrib = new RoleEquipField();
            extraAttrib.setType(key);
            LinkedHashMap<Short, FiedValue> linkedHashMap = new LinkedHashMap<>();
            extraAttrib.setField(linkedHashMap);
            if (key == 514) {
                values.forEach((name, value) -> {
                    int fieldId = attrService.getFiledIdBy(name);
                    linkedHashMap.put((short) fieldId, new FiedValue(fieldId, value));
                });
            } else if (key == 770) {
                if (level == 70) {
                    int i = 0;
                    for (Map.Entry<String, Integer> entry : values.entrySet()) {
                        String name = entry.getKey();
                        Integer value = entry.getValue();
                        i++;
                        if (i == 1) {
                            int fieldId = attrService.getFiledIdBy(name);
                            linkedHashMap.put((short) fieldId, new FiedValue(fieldId, value));
                        }
                    }
                }
            } else if (key == 1026) {
                if (level == 70) {
                    int i = 0;
                    for (Map.Entry<String, Integer> entry : values.entrySet()) {
                        String name = entry.getKey();
                        Integer value = entry.getValue();
                        i++;
                        if (i == 2) {
                            int fieldId = attrService.getFiledIdBy(name);
                            linkedHashMap.put((short) fieldId, new FiedValue(fieldId, value));
                        }
                    }
                }
            }
            equipFields.add(extraAttrib);
        });
        equipFields.forEach(fields -> roleEquip.getFields().put(fields.getType(), fields));

        roleEquip.alterUpgradeLevel(upgradeLevel);
        addUpgradeField(equip, roleEquip);

        RespIconCartoon respIconCartoon = new RespIconCartoon();
        respIconCartoon.setName(roleEquip.getName());
        respIconCartoon.setParam(roleEquip.getId() + "");
        MessagePusher.pushMessage(role, respIconCartoon);
        refreshRoleEquip(role, roleEquip);
        add(role, roleEquip);

        /**产生一个装备改造等级改变事件*/
        EventDispatcher.getInstance().fireEvent(new EquipUpgradeLevelChangeEvent(EventType.EQUIP_UPGRADE_LEVEL_CHANGE, role, roleEquip, roleEquip.queryUpgradeLevel()));

        return roleEquip;
    }

    /**
     * 计算完美度
     *
     * @param roleEquip
     * @return
     */
    public double countPerfect(RoleEquip roleEquip) {
        List<Short> fields = Arrays.asList((short) 514, (short) 770, (short) 1026, (short) 2050, (short) 3074/*, (short) 6914*/);
        List<Short> extra = Arrays.asList((short) 3, (short) 7, (short) 8, (short) 10, (short) 14);
        try {
            Equip equip = EquipDataPool.getByName(roleEquip.getName());
            BigDecimal rate = new BigDecimal(0);
            int level = roleEquip.queryLevel();

            for (Short key : fields) {
                RoleEquipField roleEquipField = roleEquip.getFields().get(key);
                if (roleEquipField != null) {
                    LinkedHashMap<Short, FiedValue> linkedHashMap = roleEquipField.getField();
                    for (Map.Entry<Short, FiedValue> entry : linkedHashMap.entrySet()) {
                        FiedValue value = entry.getValue();
                        Attribute attribute = attrService.getAttr(entry.getKey());
                        int max = 0;
                        if (extra.contains(attribute.getAttrId())) {
                            max = attrService.getSuitFiledMax(attribute.getAttrId(), level, equip.getPosition());
                        } else {
                            max = attrService.getFiledMax(attribute.getAttrId(), level, equip.getPosition());
                        }
                        BigDecimal curr = new BigDecimal(attrService.getValue(value.getValue()));
                        BigDecimal result = new BigDecimal(max);
                        BigDecimal temp = curr.divide(result, 5, BigDecimal.ROUND_HALF_UP);
                        rate = rate.add(temp);
                    }
                }
            }
            int perfect = rate.divide(new BigDecimal(7), 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(10000)).intValue();
            FiedValue value = roleEquip.getFields().get((short) 1).getField().get((short) 889);
            if (value != null) {
                value.setValue(perfect);
            }
            int oldPerfect = roleEquip.getPerfect();
            roleEquip.setPerfect(perfect);
            if (roleEquip.getPerfect() != oldPerfect) {
                /**产生一个装备完美度改变事件*/
                Role role = SpringUtils.getRoleService().getOnlinePlayer(roleEquip.getRoleId());
                EventDispatcher.getInstance().fireEvent(new EquipPerfectChangeEvent(EventType.EQUIP_PERFECT_CHANGE, role, roleEquip, roleEquip.getPerfect()));
            }
//            logger.error("装备完美度=={}=={}", perfect, rate.divide(new BigDecimal(7), 4, BigDecimal.ROUND_HALF_UP).doubleValue());
            return rate.divide(new BigDecimal(7), 4, BigDecimal.ROUND_HALF_UP).doubleValue();
        } catch (Exception e) {
            log.error("计算完美度报错==={}", Lang.getStackTrace(e));
            return 0;
        }

    }


    /**
     * 获得未鉴定装备
     */
    public void getNotIdentifyEquip(int level, Role role, short newPos) {
        List<Integer> set = Arrays.asList(1, 2, 2, 3, 3, 10, 10);
        Random random = new Random();
        int index = random.nextInt(set.size());
        int pos = set.get(index);

        RoleEquip roleEquip = new RoleEquip();
        List<String> arrayList = EquipDataPool.getNamesBy(level, pos);
        if (arrayList.isEmpty()) {
            return;
        }
        int i = random.nextInt(arrayList.size());
        String equipName = arrayList.get(i);
        int addNum = 1;
        for (RoleEquip oldEquip : role.getEquipBox().getEquips().values()) {
            if (oldEquip == null || oldEquip.getPosition() > 165 || oldEquip.getPosition() < 41 || Strings.isEmpty(oldEquip.getType()) || !oldEquip.getType().equals("未鉴定装备")) {
                continue;
            }
            if (oldEquip.getName().equals(equipName)) {//已有相同未鉴定装备 直接叠加
                addNum = bagService.mergeItem(role, oldEquip, 10, addNum);
                if (addNum <= 0) {
                    refreshRoleEquip(role, oldEquip);
                    role.save();
                    MessagePusher.pushMessage(role, new RespIconCartoon(equipName));
                    MessagePusher.pushMessage(role, new RespMsg("恭喜，你获得了一件#R" + equipName + "#n。"));
                    return;
                }
            }
        }
        Equip equip = EquipDataPool.getByName(equipName);

        int id = mallService.getRoleEquipId();
        roleEquip.setId(id);

        roleEquip.setName(equipName);
        roleEquip.setRoleId(role.getRoleId());
        roleEquip.setPosition(newPos);
        // 添加物品信息
        {
            RoleEquipField roleEquipField = new RoleEquipField();
            roleEquipField.setType((short) 1);
            String color = "金色";

            LinkedHashMap<Short, FiedValue> basicAttrNew = getBasicAttrNew(equip, roleEquip, color, false);
            roleEquipField.setField(basicAttrNew);
            roleEquip.getFields().put(roleEquipField.getType(), roleEquipField);
            RoleEquipField basicAttNew = getBasicAttNew(equip);
            roleEquip.getFields().put(basicAttNew.getType(), basicAttNew);
        }
        roleEquip.setType("未鉴定装备");
        roleEquip.getFields().get((short) 1).getField().get((short) 207).setValue(20000);//未鉴定装备售价 固定20000
        add(role, roleEquip);
        refreshRoleEquip(role, roleEquip);
        MessagePusher.pushMessage(role, new RespIconCartoon(roleEquip.getName()));
        MessagePusher.pushMessage(role, new RespMsg("恭喜，你获得了一件#R" + roleEquip.getName() + "#n。"));

    }

    /**
     * 刷新法宝灵气
     */
    public void refillArtifactNimbus(IoSession session, int id) {
        Role role = SessionUtils.getRoleBySession(session);
        if (role == null) {
            return;
        }
        RoleEquip roleEquip = getEquipById(role, id);
        if (roleEquip == null) {
            return;
        }
        int cash = FormulaUtil.getRefillArtifactNimbusNeedCash(roleEquip.queryArtifactNimbus(), roleEquip.queryLevel());
        /**先判断代金券*/
        String successMessage = "你花费了{0}{1}，成功恢复了法宝灵气。";
        if (role.getVoucher() < cash) {
            if (role.getMoney() < cash) {
                MessagePusher.pushMessage(session, new RespMsg(MessageFormat.format(ROLE_RESOURCE_NOT_ENOUGH, MONEY_NAME)));
                return;
            } else {
                roleService.subtractMoney(role, cash);
                successMessage = MessageFormat.format(successMessage, AsktaoUtil.getMoneyFormat(cash), "文金钱");
            }
        } else {
            roleService.subtractVoucher(role, cash);
            successMessage = MessageFormat.format(successMessage, AsktaoUtil.getMoneyFormat(cash), "文代金券");
        }

        roleEquip.addArtifactNimbus(FormulaUtil.getArtifactMaxNimbus(roleEquip.queryLevel()));
        refreshRoleEquip(role, roleEquip);
        role.save();
        MessagePusher.pushMessage(session, new RespNotifyMiscEx(successMessage));

    }

    /**
     * 取法宝基础属性
     */
    public LinkedHashMap<Short, FiedValue> getArtifactBasicAttr(Equip equip, RoleEquip roleEquip, String color) {
        LinkedHashMap<Short, FiedValue> linkedHashMap = new LinkedHashMap<>();
        List<FiedValue> values = new ArrayList<>();
        values.add(new FiedValue(205, 0));
        values.add(new FiedValue(206, 8192));//光效类型?
        values.add(new FiedValue(74, 7));
        values.add(new FiedValue(34, 0));
        values.add(new FiedValue(63, 0));//亲密度
        values.add(new FiedValue(902, 1));
        values.add(new FiedValue(25, 0));
        values.add(new FiedValue(928, 1));
        values.add(new FiedValue(31, 1));
        values.add(new FiedValue(118, 2000));//当前灵气
        values.add(new FiedValue(202, 9));//装备部位
        values.add(new FiedValue(40, equip.getIcon()));
        values.add(new FiedValue(207, equip.getValue() * 5));
        values.add(new FiedValue(1, equip.getKey_name()));
        values.add(new FiedValue(306, String.valueOf(roleEquip.getId())));
        values.add(new FiedValue(271, 0));
        values.add(new FiedValue(270, 0));
        values.add(new FiedValue(899, new Random().nextInt(5) + 1));//相性
        values.add(new FiedValue(209, ""));
        values.add(new FiedValue(84, roleEquip.getId()));
        values.add(new FiedValue(55, 1830));
        values.add(new FiedValue(901, ""));//法宝技能 qinmi_wujian
        values.add(new FiedValue(203, 1));
        values.forEach(value -> linkedHashMap.put(value.getType(), value));
        return linkedHashMap;
    }


    public RoleDaofa getDaofaData(int level) {
        RoleDaofa nextLevel = DataCache.DAOFA_LIST.get(level);
        if (nextLevel == null){
            nextLevel = DataCache.DAOFA_LIST.get(24);
        }
        return nextLevel;
    }

    /**
     * 魂器基础属性
     *
     * @param equip
     * @param roleEquip
     */
    public LinkedHashMap<Short, FiedValue> getHunQiBasicAttr(Equip equip, RoleEquip roleEquip) {
        LinkedHashMap<Short, FiedValue> linkedHashMap = new LinkedHashMap<>();
        List<FiedValue> values = new ArrayList<>();
        values.add(new FiedValue(270, 0));//限制
        values.add(new FiedValue(40, equip.getIcon()));//ICON
        values.add(new FiedValue(1, equip.getKey_name()));
        values.add(new FiedValue(965, 1));//技能等级
        values.add(new FiedValue(966, 0));//？？？
        values.add(new FiedValue(985, 0));//？？？
        values.add(new FiedValue(209, "金色"));
        values.add(new FiedValue(207, equip.getValue() * 5));//出手价格
        values.add(new FiedValue(203, 1));//数量
        values.add(new FiedValue(206, 8192));//光效类型? attr
        values.add(new FiedValue(261, 0)); //LOCK
        values.add(new FiedValue(306, String.valueOf(roleEquip.getId())));
        values.add(new FiedValue(74, 30));//物品类型
        values.add(new FiedValue(205, equip.getReq_level()));
        values.add(new FiedValue(202, equip.getPosition()));//装备位置
        values.add(new FiedValue(264, ""));
        values.add(new FiedValue(38, 0));
        values.add(new FiedValue(84, roleEquip.getId()));
        values.add(new FiedValue(215, 0));//MAX_REQ_LEVEL
        values.add(new FiedValue(34, 0));

        values.forEach(value -> linkedHashMap.put(value.getType(), value));
        return linkedHashMap;
    }

    /**
     * 取装备基础属性
     */
    public LinkedHashMap<Short, FiedValue> getBasicAttrNew(Equip equip, RoleEquip roleEquip, String color, boolean isIdentify) {
        LinkedHashMap<Short, FiedValue> linkedHashMap = new LinkedHashMap<>();
        List<FiedValue> values = new ArrayList<>();
        if (equip.getPosition() >= 4 && equip.getPosition() <= 6) {
            values.add(new FiedValue(452, 0));//首饰转换限制时间
            values.add(new FiedValue(451, 0));//首饰转换次数
            if (equip.getReq_level() < 80) {//小于80级能叠加
                values.add(new FiedValue(282, 2));//能否叠加
            }
        }
        values.add(new FiedValue(889, 0));
        values.add(new FiedValue(205, equip.getReq_level()));
        values.add(new FiedValue(203, 1));//
        values.add(new FiedValue(269, 0));//套装相性
        values.add(new FiedValue(74, 1));//物品类型
        values.add(new FiedValue(34, 0));
        values.add(new FiedValue(807, 0));
        values.add(new FiedValue(276, 0));
        values.add(new FiedValue(31, equip.getReq_level()));
        values.add(new FiedValue(198, 0));//改造完成度
        values.add(new FiedValue(44, equip.getMenpai()));
        values.add(new FiedValue(202, equip.getPosition()));
        values.add(new FiedValue(40, equip.getIcon()));
        values.add(new FiedValue(207, equip.getValue() * 5));//出手价格
        values.add(new FiedValue(208, 0));
        values.add(new FiedValue(1, equip.getKey_name()));
        values.add(new FiedValue(306, String.valueOf(roleEquip.getId())));
        values.add(new FiedValue(815, 0));
        values.add(new FiedValue(271, 0));
        values.add(new FiedValue(296, 0));
        values.add(new FiedValue(881, 0));
        values.add(new FiedValue(209, color));
        values.add(new FiedValue(84, roleEquip.getId()));
        values.add(new FiedValue(270, 0));
        values.add(new FiedValue(268, 0));//套装相性
        values.add(new FiedValue(197, (byte) (isIdentify ? 0 : 1)));
        values.add(new FiedValue(110, 0));
        values.add(new FiedValue(29, equip.getGender()));
        if (!isIdentify) {
            values.add(new FiedValue(282, 2));//未鉴定装备能叠加
        }
        values.forEach(value -> linkedHashMap.put(value.getType(), value));
        return linkedHashMap;
    }


    /**
     * 设置共鸣的属性
     */
    public void setResonanceField(Equip equip, Map.Entry<Short, FiedValue> entry, int upgradeLevel) {
        short fieldId = entry.getKey();
        Attribute attribute = SpringUtils.getBean(AttrService.class).getAttr(fieldId);
        int newValue = ToolsPub.getGongMingField(upgradeLevel, entry.getKey(), equip.getReq_level());
        entry.getValue().setType(fieldId);
        entry.getValue().setVT(attribute.getType());
        entry.getValue().setValue(newValue);
    }



    /**
     * 预览装备
     */
    public void equipPreview(Role role, Equip equip, RoleEquip roleEquip, byte type) {
        int destLevel = 0;
        boolean isPre = false;
        if (type == UpgradeType.UPGRADE_EQUIP_UPGRADE) {
            destLevel++;
            isPre = true;
        } else if (type == UpgradeType.EQUIP_EVOLVE_PREVIEW) {
            /**进化预览*/
            log.error("进化预览");
            evolvePreview(role, roleEquip);
            return;
        }
        LinkedHashMap<Short, RoleEquipField> linkedHashMap = new LinkedHashMap<>();
        for (Map.Entry<Short, RoleEquipField> entry : roleEquip.getFields().entrySet()) {
            RoleEquipField equipField = new RoleEquipField();
            equipField.setField(new LinkedHashMap<>());
            equipField.setType(entry.getValue().getType());
            for (Map.Entry<Short, FiedValue> valueEntry : entry.getValue().getField().entrySet()) {
                FiedValue fiedValue = new FiedValue();
                fiedValue.setValue(valueEntry.getValue().getValue());
                fiedValue.setType(valueEntry.getValue().getType());
                fiedValue.setVT(valueEntry.getValue().getVT());
                equipField.getField().put(fiedValue.getType(), fiedValue);
            }
            linkedHashMap.put(equipField.getType(), equipField);
        }

        int tempLevel = roleEquip.queryUpgradeLevel();
        RoleEquipField roleEquipField = linkedHashMap.get((short) 6914);
        if (roleEquipField != null && roleEquipField.getField() != null) {
            for (Map.Entry<Short, FiedValue> entry : roleEquipField.getField().entrySet()) {
                setResonanceField(equip, entry, tempLevel + destLevel);
            }
        }

        LinkedHashMap<Short, RoleEquipField> equipFields = SpringUtils.getEquipService().calcAttribOneKey(roleEquip.queryLevel(), roleEquip.queryUpgradeLevel(), roleEquip.queryEquipPos(false), isPre);
        equipFields.forEach(linkedHashMap::put);

        RespPreUpgradeEquip preUpgradeEquip = new RespPreUpgradeEquip();
        preUpgradeEquip.setPosition((byte) roleEquip.getPosition());
        preUpgradeEquip.setUpgrade_type(type);
        preUpgradeEquip.setEquipFields(transferList(linkedHashMap));
        MessagePusher.pushMessage(role, preUpgradeEquip);

    }

    private void evolvePreview(Role role, RoleEquip roleEquip) {
        String json = JsonUtils.object2String(roleEquip);
        RoleEquip newEquip = JsonUtils.string2Object(json, RoleEquip.class);
        alterEquipFromEvolve(newEquip, EquipDataPool.getByName(EquipDataPool.getByName(newEquip.getName()).getUpgradeName()));
        RespPreUpgradeEquip preUpgradeEquip = new RespPreUpgradeEquip();
        preUpgradeEquip.setPosition((byte) roleEquip.getPosition());
        preUpgradeEquip.setUpgrade_type(UpgradeType.EQUIP_EVOLVE_PREVIEW);
        preUpgradeEquip.setEquipFields(transferList(newEquip.getFields()));
        MessagePusher.pushMessage(role, preUpgradeEquip);
    }


    public FiedValue randomField(Equip equip, RoleEquip roleEquip, RoleEquip oldRoleEquip, boolean isX5) {
        if (equip.getReq_level() < 80) {
            return null;
        }
        LinkedHashMap<Short, FiedValue> linkedHashMap;
        LinkedHashMap<Short, FiedValue> posLinkedHashMap;

        LinkedHashMap<Short, FiedValue> pinkLinkedHashMap;
        LinkedHashMap<Short, FiedValue> pinkPosLinkedHashMap;
        if (oldRoleEquip == null) {
            {
                RoleEquipField roleEquipField = roleEquip.getFields().get((short) 514);//属性
                if (roleEquipField == null) {
                    roleEquipField = new RoleEquipField();
                    roleEquipField.setType((short) 514);
                    roleEquip.getFields().put(roleEquipField.getType(), roleEquipField);
                }
                linkedHashMap = roleEquipField.getField();//属性
                if (linkedHashMap == null) {
                    linkedHashMap = new LinkedHashMap<>();
                    roleEquipField.setField(linkedHashMap);
                }

                RoleEquipField posRoleEquipField = roleEquip.getFields().get((short) 5378);//属性位置
                if (posRoleEquipField == null) {
                    posRoleEquipField = new RoleEquipField();
                    posRoleEquipField.setType((short) 5378);
                    roleEquip.getFields().put(posRoleEquipField.getType(), posRoleEquipField);
                }
                posLinkedHashMap = posRoleEquipField.getField();//属性位置
                if (posLinkedHashMap == null) {
                    posLinkedHashMap = new LinkedHashMap<>();
                    posRoleEquipField.setField(posLinkedHashMap);
                }
            }

            {
                RoleEquipField roleEquipField = roleEquip.getFields().get((short) 770);//属性
                if (roleEquipField == null) {
                    roleEquipField = new RoleEquipField();
                    roleEquipField.setType((short) 770);
                    roleEquip.getFields().put(roleEquipField.getType(), roleEquipField);
                }
                pinkLinkedHashMap = roleEquipField.getField();//属性
                if (pinkLinkedHashMap == null) {
                    pinkLinkedHashMap = new LinkedHashMap<>();
                    roleEquipField.setField(pinkLinkedHashMap);
                }

                RoleEquipField posRoleEquipField = roleEquip.getFields().get((short) 5634);//属性位置
                if (posRoleEquipField == null) {
                    posRoleEquipField = new RoleEquipField();
                    posRoleEquipField.setType((short) 5634);
                    roleEquip.getFields().put(posRoleEquipField.getType(), posRoleEquipField);
                }
                pinkPosLinkedHashMap = posRoleEquipField.getField();//属性位置
                if (pinkPosLinkedHashMap == null) {
                    pinkPosLinkedHashMap = new LinkedHashMap<>();
                    posRoleEquipField.setField(pinkPosLinkedHashMap);
                }
            }

        } else {
            {
                RoleEquipField roleEquipField = oldRoleEquip.getFields().get((short) 514);//属性
                if (roleEquipField == null) {
                    roleEquipField = new RoleEquipField();
                    roleEquipField.setType((short) 514);
                    oldRoleEquip.getFields().put(roleEquipField.getType(), roleEquipField);
                }
                linkedHashMap = roleEquipField.getField();//属性
                if (linkedHashMap == null) {
                    linkedHashMap = new LinkedHashMap<>();
                    roleEquipField.setField(linkedHashMap);
                }

                RoleEquipField posRoleEquipField = oldRoleEquip.getFields().get((short) 5378);//属性位置
                if (posRoleEquipField == null) {
                    posRoleEquipField = new RoleEquipField();
                    posRoleEquipField.setType((short) 5378);
                    oldRoleEquip.getFields().put(posRoleEquipField.getType(), posRoleEquipField);
                }
                posLinkedHashMap = posRoleEquipField.getField();//属性位置
                if (posLinkedHashMap == null) {
                    posLinkedHashMap = new LinkedHashMap<>();
                    posRoleEquipField.setField(posLinkedHashMap);
                }
            }

            {
                RoleEquipField roleEquipField = oldRoleEquip.getFields().get((short) 770);//属性
                if (roleEquipField == null) {
                    roleEquipField = new RoleEquipField();
                    roleEquipField.setType((short) 770);
                    oldRoleEquip.getFields().put(roleEquipField.getType(), roleEquipField);
                }
                pinkLinkedHashMap = roleEquipField.getField();//属性
                if (pinkLinkedHashMap == null) {
                    pinkLinkedHashMap = new LinkedHashMap<>();
                    roleEquipField.setField(pinkLinkedHashMap);
                }

                RoleEquipField posRoleEquipField = oldRoleEquip.getFields().get((short) 5634);//属性位置
                if (posRoleEquipField == null) {
                    posRoleEquipField = new RoleEquipField();
                    posRoleEquipField.setType((short) 5634);
                    oldRoleEquip.getFields().put(posRoleEquipField.getType(), posRoleEquipField);
                }
                pinkPosLinkedHashMap = posRoleEquipField.getField();//属性位置
                if (pinkPosLinkedHashMap == null) {
                    pinkPosLinkedHashMap = new LinkedHashMap<>();
                    posRoleEquipField.setField(pinkPosLinkedHashMap);
                }
            }
        }
        FiedValue fiedValue = randomOne(equip, linkedHashMap);


        FiedValue randFieldValue = new FiedValue(fiedValue.getType(), fiedValue.getValue());

        if (isX5) {
            fiedValue.setValue(5);
            fiedValue.setType((short) 221);
            fiedValue.setVT((byte) 2);
            linkedHashMap.put(fiedValue.getType(), fiedValue);
        }else {
            linkedHashMap.put(fiedValue.getType(), fiedValue);
        }
        String content = Json.toJson(fiedValue);
        FiedValue posFieldValue = Json.fromJson(FiedValue.class, content);
        posFieldValue.setValue((short) linkedHashMap.size());//属性位置
        posLinkedHashMap.put(fiedValue.getType(), posFieldValue);

        return randFieldValue;
    }


    /**
     * @param
     * @param equip
     * @param
     * @param
     * @param
     */
    public void randomX5(Equip equip, RoleEquip oldRoleEquip, FiedValue fiedValue) {
        if (equip.getReq_level() < 80) {
            return;
        }
        LinkedHashMap<Short, FiedValue> linkedHashMap = null;
        LinkedHashMap<Short, FiedValue> posLinkedHashMap = null;
        LinkedHashMap<Short, FiedValue> pinkLinkedHashMap = null;
        LinkedHashMap<Short, FiedValue> pinkPosLinkedHashMap = null;
        {
            {
                RoleEquipField roleEquipField = oldRoleEquip.getFields().get((short) 514);//属性
                if (roleEquipField == null) {
                    roleEquipField = new RoleEquipField();
                    roleEquipField.setType((short) 514);
                    oldRoleEquip.getFields().put(roleEquipField.getType(), roleEquipField);
                }
                linkedHashMap = roleEquipField.getField();//属性
                if (linkedHashMap == null) {
                    linkedHashMap = new LinkedHashMap<>();
                    roleEquipField.setField(linkedHashMap);
                }

                RoleEquipField posRoleEquipField = oldRoleEquip.getFields().get((short) 5378);//属性位置
                if (posRoleEquipField == null) {
                    posRoleEquipField = new RoleEquipField();
                    posRoleEquipField.setType((short) 5378);
                    oldRoleEquip.getFields().put(posRoleEquipField.getType(), posRoleEquipField);
                }
                posLinkedHashMap = posRoleEquipField.getField();//属性位置
                if (posLinkedHashMap == null) {
                    posLinkedHashMap = new LinkedHashMap<>();
                    posRoleEquipField.setField(posLinkedHashMap);
                }
            }

            {
                RoleEquipField roleEquipField = oldRoleEquip.getFields().get((short) 770);//属性
                if (roleEquipField == null) {
                    roleEquipField = new RoleEquipField();
                    roleEquipField.setType((short) 770);
                    oldRoleEquip.getFields().put(roleEquipField.getType(), roleEquipField);
                }
                pinkLinkedHashMap = roleEquipField.getField();//属性
                if (pinkLinkedHashMap == null) {
                    pinkLinkedHashMap = new LinkedHashMap<>();
                    roleEquipField.setField(pinkLinkedHashMap);
                }

                RoleEquipField posRoleEquipField = oldRoleEquip.getFields().get((short) 5634);//属性位置
                if (posRoleEquipField == null) {
                    posRoleEquipField = new RoleEquipField();
                    posRoleEquipField.setType((short) 5634);
                    oldRoleEquip.getFields().put(posRoleEquipField.getType(), posRoleEquipField);
                }
                pinkPosLinkedHashMap = posRoleEquipField.getField();//属性位置
                if (pinkPosLinkedHashMap == null) {
                    pinkPosLinkedHashMap = new LinkedHashMap<>();
                    posRoleEquipField.setField(pinkPosLinkedHashMap);
                }
            }
        }

        if (linkedHashMap.get(fiedValue.getType()) == null) {
            linkedHashMap.put(fiedValue.getType(), fiedValue);
            FiedValue posFiedValue = new FiedValue();
            posFiedValue.setValue(fiedValue.getValue());
            posFiedValue.setType(fiedValue.getType());
            posFiedValue.setVT(fiedValue.getVT());
            posLinkedHashMap.put(posFiedValue.getType(), posFiedValue);
        } else {
            pinkLinkedHashMap.put(fiedValue.getType(), fiedValue);
            FiedValue posFiedValue = new FiedValue();
            posFiedValue.setValue(fiedValue.getValue());
            posFiedValue.setType(fiedValue.getType());
            posFiedValue.setVT(fiedValue.getVT());
            pinkPosLinkedHashMap.put(posFiedValue.getType(), posFiedValue);
        }
//        logger.error("相五属性=={}=={}=={}=={}",Json.toJson(linkedHashMap),Json.toJson(posLinkedHashMap),Json.toJson(pinkLinkedHashMap),Json.toJson(pinkPosLinkedHashMap));
    }

    private int getRandom(List<Integer> Jade1){
        Random random = new Random();
        int index = random.nextInt(Jade1.size());
        if (index == 0){
            index = random.nextInt(Jade1.size());
        }
        return Jade1.get(index);
    }

    /**
     * 转换首饰
     */
    public void transformField(Equip equip, LinkedHashMap<Short, RoleEquipField> linkedHashMap, short pos) {
        LinkedHashMap<Short, FiedValue> blueFieldMap = linkedHashMap.get((short) 514).getField();
        LinkedHashMap<Short, FiedValue> blueFieldPosMap = linkedHashMap.get((short) 5378).getField();
        LinkedHashMap<Short, FiedValue> pinkFieldMap = linkedHashMap.get((short) 770).getField();
        LinkedHashMap<Short, FiedValue> pinkFieldPosMap = linkedHashMap.get((short) 5634).getField();
        Random random = new Random();
        int result = 0;
        boolean blue = false;
        while (true) {
            if (equip.getPosition() == 5) {
                // 玉佩11
                result = getRandom(Jade);
                if (attPerfect.contains(result)){
                    result = getRandom(Jade);
                }
            } else if (equip.getPosition() == 4) {
                // 项链
                result = getRandom(Necklace);
                if (attPerfect.contains(result)){
                    result = getRandom(Necklace);
                }
            } else if (equip.getPosition() == 6) {
                // 手镯
                result = getRandom(Bracelet);
                if (attPerfect.contains(result)){
                    result = getRandom(Bracelet);
                }
            }
            short field = (short) result;
            if (field == 0) {
                /**避免出现丢失属性的情况 确保属性id不为0*/
                continue;
            }
            if (field == 221) {//所有相性
                if (blueFieldMap.get(field) != null || pinkFieldMap.get(field) != null) {
                    /**已有所有相性就继续循环 一件首饰 只能有一条所有相性**/
                    continue;
                }
            }
            if (blueFieldMap.get(field) == null) {
                blue = true;
                break;
            } else {
                if (pinkFieldMap.get(field) == null) {
                    break;
                }
            }
        }
        FiedValue fiedValue = new FiedValue();
        FiedValue posFieldValue = new FiedValue();
        fiedValue.setType((short) result);
        posFieldValue.setType((short) result);
        Attribute attribute = attrService.getAttr((short) result);
        fiedValue.setVT(attribute.getType());
        posFieldValue.setVT(attribute.getType());
        int min = attrService.getFiledMin(result, equip.getReq_level(), equip.getPosition());
        int max = attrService.getFiledMax(result, equip.getReq_level(), equip.getPosition());
        int subMin, subMax;
        int rand = random.nextInt(10000);
        if (1== rand){
            subMin = max * 8 / 10;
            subMax = max;
        }else {
            rand = random.nextInt(10000);
            if (1==rand){
                subMin = max * 6 / 10;
                subMax = max * 8 / 10;
            }else {
                subMin = min;
                subMax = max * 6 / 10;
            }
        }

        int value =0;
        if (subMax > subMin) {
            value = random.nextInt(subMax - subMin) + subMin + 1;
        } else {
            value = subMax;
        }
        fiedValue.setValue(value);
        posFieldValue.setValue(pos);
        if (blue) {
            blueFieldMap.put(fiedValue.getType(), fiedValue);
            blueFieldPosMap.put(posFieldValue.getType(), posFieldValue);
        } else {
            pinkFieldMap.put(fiedValue.getType(), fiedValue);
            pinkFieldPosMap.put(posFieldValue.getType(), posFieldValue);
        }
    }

    /**
     * 首饰随机一条属性
     */
    private FiedValue randomOne(Equip equip, LinkedHashMap linkedHashMap1) {
        Random random = new Random();
        int result = 0;
        while (true) {
            if (equip.getPosition() == 5) {
                // 玉佩11
                result = getRandom(Jade);
                if (attPerfect.contains(result)){
                    result = getRandom(Jade);
                }
            } else if (equip.getPosition() == 4) {
                // 项链
                result = getRandom(Necklace);
                if (attPerfect.contains(result)){
                    result = getRandom(Necklace);
                }
            } else if (equip.getPosition() == 6) {
                // 手镯
                result = getRandom(Bracelet);
                if (attPerfect.contains(result)){
                    result = getRandom(Bracelet);
                }
            }
            short shuxin = (short) result;
            if (linkedHashMap1.get(shuxin) == null) {
                break;
            }
        }
        FiedValue fiedValue = new FiedValue();
        short fieldId = (short) result;
        fiedValue.setType(fieldId);
        Attribute attribute = attrService.getAttr(fieldId);
        fiedValue.setVT(attribute.getType());
        int min = attrService.getFiledMin(result, equip.getReq_level(), equip.getPosition());
        int max = attrService.getFiledMax(result, equip.getReq_level(), equip.getPosition());

        /**60%概率 min至0.6*max， 30%概率 0.6*max至0.8*max, 10%概率 0.8*max至max*/
        int subMin, subMax;
        int rand = random.nextInt(10000);
        if (1== rand){
            subMin = max * 8 / 10;
            subMax = max;
        }else {
            rand = random.nextInt(10000);
            if (1==rand){
                subMin = max * 6 / 10;
                subMax = max * 8 / 10;
            }else {
                subMin = min;
                subMax = max * 6 / 10;
            }
        }

        int value;
        if (subMax > subMin) {
            value = random.nextInt(subMax - subMin) + subMin + 1;
        } else {
            value = subMax;
        }

        fiedValue.setValue(value);
        return fiedValue;
    }

    /**
     * 首饰合成时生成的属性值达到70%最大值时发谣言
     */
    private void numorJewelry(Role role, FiedValue fiedValue, Equip equip) {
        if (role == null || fiedValue == null || equip == null) {return;}

        /**达到70%最大值时发谣言*/
        int max = attrService.getFiledMax(fiedValue.getType(), equip.getReq_level(), equip.getPosition());
        if ((Integer)fiedValue.getValue() >= (max * 7 / 10)) {
            Attribute attr = attrService.getAttr(fiedValue.getType());
            String addAttr = attr.getValuename() + fiedValue.getValue();
            if (attrService.isPercentFieldName(attr.getName())) {addAttr += "%";}
            String content = I18nIdDataPool.getI18nContent(I18nId.PMT_2000, role.getName(), addAttr, equip.getKey_name());
            SpringUtils.getChatService().sendNumor(content, Const.BRODCAST_MSG_TYPE_ROLE);
        }
    }

    /**
     * 掉落首饰
     */
    public RoleEquip getJewelry(Role role, Equip equip, String color, int num, int limitNumber, RoleEquip oldEquip, short pos, boolean isX5, boolean isLimit) {

        /**小于80的首饰可以叠加10个*/
        if (equip.getReq_level() < 80) {
            EquipBox equipBox = role.getEquipBox();
            Set<RoleEquip> equips = new HashSet<>(equipBox.getEquips().values());
            for (RoleEquip roleEquip : equips) {
                if (roleEquip == null) {
                    continue;
                }
                if (!roleEquip.getName().equals(equip.getKey_name())) {
                    continue;
                }
                if (roleEquip.getPosition() < 41 || roleEquip.getPosition() > 165) {
                    continue;
                }
                /**物品限制相同的才让叠加*/
                if (isLimit == roleEquip.isEverLimit()) {
                    num = bagService.mergeItem(role, roleEquip, 10, num);
                }
                if (num <= 0) {
                    return roleEquip;
                }
            }
        }


        RoleEquip roleEquip = new RoleEquip();
        roleEquip.setId(mallService.getRoleEquipId());

        roleEquip.setName(equip.getKey_name());
        roleEquip.setRoleId(role.getRoleId());
        roleEquip.setPosition(pos);

        RoleEquipField roleEquipField = new RoleEquipField();
        roleEquipField.setType((short) 1);
        LinkedHashMap<Short, FiedValue> basicAttrNew = getBasicAttrNew(equip, roleEquip, color, true);
        roleEquipField.setField(basicAttrNew);
        roleEquip.getFields().put(roleEquipField.getType(), roleEquipField);
        RoleEquipField basicAttNew = getBasicAttNew(equip);
        roleEquip.getFields().put(basicAttNew.getType(), basicAttNew);
        if (limitNumber > 0) {
            roleEquip.addLimitTime(limitNumber);
        }

        FiedValue fiedValue = roleEquip.getFields().get((short) 1).getField().get((short) 203);
        if (equip.getReq_level() >= 80) {
            FiedValue randFieldValue = randomField(equip, roleEquip, oldEquip, isX5);
            numorJewelry(role, randFieldValue, equip);
        }
        fiedValue.setValue(num);
        if (equip.getReq_level() >= 80) {
            roleEquip.setType("高级首饰");
        } else {
            roleEquip.setType("低级首饰");
        }
        if (isLimit) {
            roleEquip.setEquipValue(FieldValuePosConst.LIMIT, 2);
        }
        add(role, roleEquip);
        refreshRoleEquip(role, roleEquip);
        RespIconCartoon respIconCartoon = new RespIconCartoon();
        respIconCartoon.setName(roleEquip.getName());
        respIconCartoon.setParam(roleEquip.getId() + "");
        MessagePusher.pushMessage(role, respIconCartoon);
        return roleEquip;
    }


    /**
     * @param role
     * @param equipName 获取指定的首饰
     * @param isX5      是否是相五属性
     * @return
     */
//    public RoleEquip getJewelry(Role role, String equipName, boolean isX5, int num, boolean isLimit) {
//        Equip equip = EquipDataPool.getByName(equipName);
//        short newPos = SpringUtils.getBean(BagService.class).getPos(role, false);
//        if (newPos <= 0) {
//            MessagePusher.pushMessage(role, new RespMsg("你的包裹已满，无法获得#R" + equip.getName() + "#n。"));
//            return null;
//        }
//        return getJewelry(role, equip, "金色", num, 0, null, newPos, isX5, isLimit);
//
//    }

    /**
     * 掉落首饰
     */
    public RoleEquip getJewelryNew(Role role, String equipName, int num,String oldName, boolean isLimit) {
        Equip equip = EquipDataPool.getByName(equipName);
        short pos = SpringUtils.getBean(BagService.class).getPos(role, false);
        if (pos <= 0) {
            MessagePusher.pushMessage(role, new RespMsg("你的包裹已满，无法获得#R" + equip.getName() + "#n。"));
            return null;
        }
        String[] strings = {"x5","10技"//80级
                ,"22敏","22力","22灵","22体"//90级
                ,"2*25敏","2*25力","2*25灵","2*25体","2*10技","25敏","25力","25灵","25体"//100级
                ,"2*x5","2*27敏","2*27力","2*27灵","2*27体","27敏","27力","27灵","27体"//110
                ,"2*x5","2*30敏","2*30力","2*30灵","2*30体" ,"30敏","30力","30灵","30体" //120    (x5+2*体+2*敏)
                ,"2*x5","2*32敏","2*32力","2*32灵","2*32体","32敏","32力","32灵","32体" //130   (x5+2*10力+2*30敏+10技)
                ,"2*35敏","2*35力","2*35灵","2*35体","35敏","35力","35灵","35体","4800伤害"//140   (x5+2*10力+2*30敏+10技)
                ,"2*37敏","2*37力","2*37灵","2*37体","37敏","37力","37灵","37体","2*4800伤害"//150   (x5+2*10力+2*30敏+10技)
                ,"2*40敏","2*40力","2*40灵","2*40体","40敏","40力","40灵","40体","2*5400伤害","5400伤害"//160   (x5+2*10力+2*30敏+10技)
                ,"2*42敏","2*42力","2*42灵","2*42体","42敏","42力","42灵","42体","2*6000伤害","6000伤害"//170   (x5+2*10力+2*30敏+10技)
                ,"4200伤害","2*4200伤害","4800伤害","2*4800伤害","3800伤害","2*3800伤害","5400伤害","2*5400伤害","6000伤害","2*6000伤害"
        };
        ArrayList<FiedValue> list = new ArrayList();
        if (oldName.contains("x5")){
            FiedValue fiedValue = new FiedValue();
            fiedValue.setValue(5);
            fiedValue.setType((short) 221);
            fiedValue.setVT((byte) 2);
            list.add(fiedValue);
            if (oldName.contains("2*x5")){
                list.add(fiedValue);
            }
        }
        if (oldName.contains("10技")){
            FiedValue fiedValue = new FiedValue();
            fiedValue.setValue(10);
            fiedValue.setType((short) 224);
            fiedValue.setVT((byte) 2);
            list.add(fiedValue);
            if (oldName.contains("2*10技")){
                list.add(fiedValue);
            }
        }
        if (oldName.contains("3800伤害")){
            FiedValue fiedValue = new FiedValue();
            fiedValue.setValue(3800);
            fiedValue.setType((short) 808);
            fiedValue.setVT((byte) 2);
            list.add(fiedValue);
            if (oldName.contains("2*3800伤害")){
                list.add(fiedValue);
            }
        }

        if (oldName.contains("4200伤害")){
            FiedValue fiedValue = new FiedValue();
            fiedValue.setValue(4200);
            fiedValue.setType((short) 808);
            fiedValue.setVT((byte) 2);
            list.add(fiedValue);
            if (oldName.contains("2*4200伤害")){
                list.add(fiedValue);
            }
        }
        if (oldName.contains("4800伤害")){
            FiedValue fiedValue = new FiedValue();
            fiedValue.setValue(4800);
            fiedValue.setType((short) 808);
            fiedValue.setVT((byte) 2);
            list.add(fiedValue);
            if (oldName.contains("2*4800伤害")){
                list.add(fiedValue);
            }
        }
        if (oldName.contains("5400伤害")){
            FiedValue fiedValue = new FiedValue();
            fiedValue.setValue(5400);
            fiedValue.setType((short) 808);
            fiedValue.setVT((byte) 2);
            list.add(fiedValue);
            if (oldName.contains("2*5400伤害")){
                list.add(fiedValue);
            }
        }
        if (oldName.contains("6000伤害")){
            FiedValue fiedValue = new FiedValue();
            fiedValue.setValue(6000);
            fiedValue.setType((short) 808);
            fiedValue.setVT((byte) 2);
            list.add(fiedValue);
            if (oldName.contains("2*6000伤害")){
                list.add(fiedValue);
            }
        }
        String shuxinStr = "";
        if(oldName.indexOf("(")>=0){
            shuxinStr = oldName.substring(oldName.indexOf("("));
        }else{
            shuxinStr = oldName;
        }

        String[] ss = {"敏","力","灵","体"};
        for (String aa : ss){
            if (shuxinStr.contains(aa)){
                FiedValue fiedValue = new FiedValue();
                if (aa.endsWith("敏")){
                    fiedValue.setType((short) 13);
                    fiedValue.setVT((byte) 2);
                }else if (aa.endsWith("力")){
                    fiedValue.setType((short) 2);
                    fiedValue.setVT((byte) 2);
                }else if (aa.endsWith("灵")){
                    fiedValue.setType((short) 9);
                    fiedValue.setVT((byte) 2);
                }else if (aa.endsWith("体")){
                    fiedValue.setType((short) 5);
                    fiedValue.setVT((byte) 2);
                }

                list.add(fiedValue);
                if (oldName.contains("22")){
                    fiedValue.setValue(22);
                }else if(oldName.contains("25")){
                    fiedValue.setValue(25);
                    if (oldName.contains("2*25"+aa)){
                        list.add(fiedValue);
                    }
                }else if(oldName.contains("27")){
                    fiedValue.setValue(27);
                    if (oldName.contains("2*27"+aa)){
                        list.add(fiedValue);
                    }
                }else if(oldName.contains("30")){
                    fiedValue.setValue(30);
                    if (oldName.contains("2*30"+aa)){
                        list.add(fiedValue);
                    }
                } else if(oldName.contains("32")){
                    fiedValue.setValue(32);
                    if (oldName.contains("2*32"+aa)){
                        list.add(fiedValue);
                    }
                }else if(oldName.contains("35")){
                    fiedValue.setValue(35);
                    if (oldName.contains("2*35"+aa)){
                        list.add(fiedValue);
                    }
                }else if(oldName.contains("37")){
                    fiedValue.setValue(37);
                    if (oldName.contains("2*37"+aa)){
                        list.add(fiedValue);
                    }
                }else if(oldName.contains("40")){
                    fiedValue.setValue(40);
                    if (oldName.contains("2*40"+aa)){
                        list.add(fiedValue);
                    }
                }else if(oldName.contains("42")){
                    fiedValue.setValue(42);
                    if (oldName.contains("2*42"+aa)){
                        list.add(fiedValue);
                    }
                }
            }
        }
        HashMap<Integer,Integer> hashMap = new HashMap();
        hashMap.put(80,1);
        hashMap.put(90,2);
        hashMap.put(100,3);
        hashMap.put(110,4);
        hashMap.put(120,5);
        hashMap.put(130,6);
        hashMap.put(140,7);
        hashMap.put(150,8);
        hashMap.put(160,8);
        hashMap.put(170,8);
        int level = equip.getReq_level();
        if (list.size() > hashMap.get(level)) {
            MessagePusher.pushMessage(role, new RespMsg("首饰属性过多！！！！！"));
            return null;
        }
        /**小于80的首饰可以叠加10个*/
        if (equip.getReq_level() < 80) {
            EquipBox equipBox = role.getEquipBox();
            Set<RoleEquip> equips = new HashSet<>(equipBox.getEquips().values());
            for (RoleEquip roleEquip : equips) {
                if (roleEquip == null) {
                    continue;
                }
                if (!roleEquip.getName().equals(equip.getKey_name())) {
                    continue;
                }
                if (roleEquip.getPosition() < 41 || roleEquip.getPosition() > 165) {
                    continue;
                }
                /**物品限制相同的才让叠加*/
                if (isLimit == roleEquip.isEverLimit()) {
                    num = bagService.mergeItem(role, roleEquip, 10, num);
                }
                if (num <= 0) {
                    return roleEquip;
                }
            }
        }


        RoleEquip roleEquip = new RoleEquip();
        roleEquip.setId(mallService.getRoleEquipId());

        roleEquip.setName(equip.getKey_name());
        roleEquip.setRoleId(role.getRoleId());
        roleEquip.setPosition(pos);

        RoleEquipField roleEquipField = new RoleEquipField();
        roleEquipField.setType((short) 1);
        LinkedHashMap<Short, FiedValue> basicAttrNew = getBasicAttrNew(equip, roleEquip, "金色", true);
        roleEquipField.setField(basicAttrNew);
        roleEquip.getFields().put(roleEquipField.getType(), roleEquipField);
        RoleEquipField basicAttNew = getBasicAttNew(equip);
        roleEquip.getFields().put(basicAttNew.getType(), basicAttNew);

        FiedValue fiedValue = roleEquip.getFields().get((short) 1).getField().get((short) 203);
        if (equip.getReq_level() >= 80) {
            for (FiedValue fiedValue1 : list) {
                randomX5(equip, roleEquip, fiedValue1);
                numorJewelry(role, fiedValue1, equip);
            }
        }
        fiedValue.setValue(num);
        if (equip.getReq_level() >= 80) {
            roleEquip.setType("高级首饰");
        } else {
            roleEquip.setType("低级首饰");
        }
        roleEquip.addLimitTime(6);
        add(role, roleEquip);
        refreshRoleEquip(role, roleEquip);
        RespIconCartoon respIconCartoon = new RespIconCartoon();
        respIconCartoon.setName(roleEquip.getName());
        respIconCartoon.setParam(roleEquip.getId() + "");
        MessagePusher.pushMessage(role, respIconCartoon);
        return roleEquip;
    }


    public RoleEquip getJewelryNew80(Role role, String equipName, int num,String oldName, boolean isLimit) {
        Equip equip = EquipDataPool.getByName(equipName);
        short pos = SpringUtils.getBean(BagService.class).getPos(role, false);
        if (pos <= 0) {
            MessagePusher.pushMessage(role, new RespMsg("你的包裹已满，无法获得#R" + equip.getName() + "#n。"));
            return null;
        }
        ArrayList<FiedValue> list = new ArrayList();
        if (oldName.contains("x5")||oldName.contains("X5")){
            FiedValue fiedValue = new FiedValue();
            fiedValue.setValue(5);
            fiedValue.setType((short) 221);
            fiedValue.setVT((byte) 2);
            list.add(fiedValue);
        }else if (oldName.contains("20敏")){
            FiedValue fiedValue = new FiedValue();
            fiedValue.setValue(20);
            fiedValue.setType((short) 13);
            fiedValue.setVT((byte) 2);
            list.add(fiedValue);
        }else if (oldName.contains("20力")){
            FiedValue fiedValue = new FiedValue();
            fiedValue.setValue(20);
            fiedValue.setType((short) 2);
            fiedValue.setVT((byte) 2);
            list.add(fiedValue);

        }else if (oldName.contains("20灵")){
            FiedValue fiedValue = new FiedValue();
            fiedValue.setValue(20);
            fiedValue.setType((short) 9);
            fiedValue.setVT((byte) 2);
            list.add(fiedValue);
        }
        /**小于80的首饰可以叠加10个*/
        if (equip.getReq_level() < 80) {
            EquipBox equipBox = role.getEquipBox();
            Set<RoleEquip> equips = new HashSet<>(equipBox.getEquips().values());
            for (RoleEquip roleEquip : equips) {
                if (roleEquip == null) {
                    continue;
                }
                if (!roleEquip.getName().equals(equip.getKey_name())) {
                    continue;
                }
                if (roleEquip.getPosition() < 41 || roleEquip.getPosition() > 165) {
                    continue;
                }
                /**物品限制相同的才让叠加*/
                if (isLimit == roleEquip.isEverLimit()) {
                    num = bagService.mergeItem(role, roleEquip, 10, num);
                }
                if (num <= 0) {
                    return roleEquip;
                }
            }
        }


        RoleEquip roleEquip = new RoleEquip();
        roleEquip.setId(mallService.getRoleEquipId());

        roleEquip.setName(equip.getKey_name());
        roleEquip.setRoleId(role.getRoleId());
        roleEquip.setPosition(pos);

        RoleEquipField roleEquipField = new RoleEquipField();
        roleEquipField.setType((short) 1);
        LinkedHashMap<Short, FiedValue> basicAttrNew = getBasicAttrNew(equip, roleEquip, "金色", true);
        roleEquipField.setField(basicAttrNew);
        roleEquip.getFields().put(roleEquipField.getType(), roleEquipField);
        RoleEquipField basicAttNew = getBasicAttNew(equip);
        roleEquip.getFields().put(basicAttNew.getType(), basicAttNew);

        FiedValue fiedValue = roleEquip.getFields().get((short) 1).getField().get((short) 203);
        if (equip.getReq_level() >= 80) {
            for (FiedValue fiedValue1 : list) {
                randomX5(equip, roleEquip, fiedValue1);
                numorJewelry(role, fiedValue1, equip);
            }
        }
        fiedValue.setValue(num);
        if (equip.getReq_level() >= 80) {
            roleEquip.setType("高级首饰");
        } else {
            roleEquip.setType("低级首饰");
        }
        roleEquip.addLimitTime(6);
        add(role, roleEquip);
        refreshRoleEquip(role, roleEquip);
        RespIconCartoon respIconCartoon = new RespIconCartoon();
        respIconCartoon.setName(roleEquip.getName());
        respIconCartoon.setParam(roleEquip.getId() + "");
        MessagePusher.pushMessage(role, respIconCartoon);
        String notice = "惊闻#R" + role.getName() + "#n玩家在#R累计充值积分#n处兑换获得#R" + oldName + "#n！真是可喜可贺！#51 #82";
        chatService.sendAdnotice(notice);
        return roleEquip;
    }


    /**
     * 合成高级首饰
     */
    public RoleEquip getHighJewelry(Equip equip, String color, Role role, int limitNumber, RoleEquip oldEquip) {
        oldEquip.setName(equip.getKey_name());

        RoleEquipField roleEquipField = new RoleEquipField();
        roleEquipField.setType((short) 1);
        LinkedHashMap<Short, FiedValue> basicAttrNew = getBasicAttrNew(equip, oldEquip, color, true);
        /**限制时间也拷贝过来*/
        FiedValue fiedValue = oldEquip.getFields().get((short) 1).getField().get((short) 270);
        if (fiedValue != null) {
            basicAttrNew.put(fiedValue.getType(), fiedValue);
        }

        roleEquipField.setField(basicAttrNew);
        if (oldEquip.getFields() == null) {
            oldEquip.setFields(new LinkedHashMap<>());
        }
        oldEquip.getFields().put(roleEquipField.getType(), roleEquipField);
        RoleEquipField equipField = getBasicAttNew(equip);
        oldEquip.getFields().put(equipField.getType(), equipField);
        if (limitNumber > 0) {
            oldEquip.addLimitTime(limitNumber);
        }

        if (equip.getReq_level() >= 80) {

            if (equip.getReq_level() >= 80) {
                FiedValue randFieldValue = randomField(equip, oldEquip, oldEquip, false);
                numorJewelry(role, randFieldValue, equip);
            }

        }
        if (equip.getReq_level() >= 80) {
            oldEquip.setType("高级首饰");
        }

        refreshRoleEquip(role, oldEquip);
        RespIconCartoon respIconCartoon = new RespIconCartoon();
        respIconCartoon.setName(oldEquip.getName());
        respIconCartoon.setParam(oldEquip.getId() + "");
        MessagePusher.pushMessage(role, respIconCartoon);

        role.save();
        return oldEquip;
    }


    /**
     * 物品名取物品
     */
    public RoleEquip getRoleEquipByName(IoSession session, String name) {
        Role role = SessionUtils.getRoleBySession(session);
        for (Map.Entry<Integer, RoleEquip> entry : role.getEquipBox().getEquips().entrySet()) {
            if (entry.getValue().getName().contains(name)) {
                return entry.getValue();
            }
        }
        return null;
    }

    /**
     * 物品名取物品
     */
    public RoleEquip getRoleEquipByName(Role role, String name) {
        for (Map.Entry<Integer, RoleEquip> entry : role.getEquipBox().getEquips().entrySet()) {
            if (entry.getValue().getName().contains(name)) {
                return entry.getValue();
            }
        }
        return null;
    }


    /**
     * 获得物品数量
     *
     * @param limit true限制 false不限制
     */
    public int getCount(String name, boolean limit, Role role) {
        int count = 0;
        for (RoleEquip roleEquip : role.getEquipBox().getEquips().values()) {
            if (roleEquip == null) {
                continue;
            }
            if (roleEquip.getPosition() < 41 | roleEquip.getPosition() >= 166) {
                continue;
            }
            if (roleEquip.getName().equals(name)) {
                if (limit) {
                    count = count + roleEquip.queryNum();
                } else {
                    if (!roleEquip.isEverLimit()) {
                        count = count + roleEquip.queryNum();
                    }
                }
            }
        }
        return count;
    }

    /**
     * 查找背包药品
     *
     * @param name
     * @param session
     */
    public int getManaMedicine(String name, IoSession session) {
        Role role = SessionUtils.getRoleBySession(session);
        int pos = 0;
        if (session == null) {
            return pos;
        }

        for (Map.Entry<Integer, RoleEquip> entry : role.getEquipBox().getEquips().entrySet()) {
            RoleEquip roleEquip = entry.getValue();
            if (roleEquip == null) {
                continue;
            }
            if (roleEquip.getPosition() < 41 | roleEquip.getPosition() >= 166) {
                continue;
            }
            if (roleEquip.getName().contains(name)) {
                pos = roleEquip.getPosition();
                break;
            }
        }
        return pos;
    }


    /**
     * 消耗叠加物品
     *
     * @param num      数量
     * @param useLimit 是否受限制 true优先使用限制交易的物品
     */
    public int delRoloEquip(String equipName, int num, boolean useLimit, IoSession session) {
        Role role = SessionUtils.getRoleBySession(session);
        return delRoloEquip(equipName, num, useLimit, role);

    }

    /**
     * 根据名字删除物品
     */
    public int delRoloEquip(String equipName, int num, boolean useLimit, Role role) {
        int limitNum = 0;
        int tempNum = num;

        Set<RoleEquip> equips = new HashSet<>(role.getEquipBox().getEquips().values());
        if (useLimit) {//先扣除限制物品
            for (RoleEquip roleEquip : equips) {
                if (roleEquip == null || roleEquip.getPosition() > 165 || roleEquip.getPosition() <= 40 || !roleEquip.getName().equals(equipName)) { //如果装备为空或者不在背包
                    continue;
                }
                if (roleEquip.isEverLimit()) {//是限制物品
                    int count = roleEquip.queryNum();
                    if (count > tempNum) {//扣除数量 更新物品属性
                        delEquipNum(role, roleEquip, tempNum);
                        limitNum = tempNum;
                        tempNum = 0;
                        break;
                    } else {//数量小于或者等于 删除物品
                        delEquipNum(role, roleEquip, count);
                        limitNum = limitNum + count;
                        tempNum = tempNum - count;
                        if (tempNum <= 0) {
                            break;
                        }
                    }
                }
            }
            if (tempNum <= 0) {
                return limitNum;
            }
            for (RoleEquip roleEquip : equips) {
                if (roleEquip == null || roleEquip.getPosition() > 165 || roleEquip.getPosition() <= 40 || !roleEquip.getName().equals(equipName) || roleEquip.isEverLimit()) {
                    continue;
                }
                int count = roleEquip.queryNum();
                if (count > tempNum) {//扣除数量 更新物品属性
                    delEquipNum(role, roleEquip, tempNum);
                    break;
                } else {//数量小于或者等于 删除物品
                    delEquipNum(role, roleEquip, count);
                    tempNum = tempNum - count;
                    if (tempNum <= 0) {
                        break;
                    }
                }
            }
            return limitNum;
        } else {//只扣除不限制物品
            for (RoleEquip roleEquip : equips) {
                if (roleEquip == null || roleEquip.getPosition() > 165 || roleEquip.getPosition() <= 40 || !roleEquip.getName().equals(equipName) || roleEquip.isEverLimit()) {
                    continue;
                }
                int count = roleEquip.queryNum();
                if (count > tempNum) {//扣除数量 更新物品属性
                    delEquipNum(role, roleEquip, tempNum);
                    break;
                } else {//数量小于或者等于 删除物品
                    delEquipNum(role, roleEquip, count);
                    tempNum = tempNum - count;
                    if (tempNum <= 0) {
                        break;
                    }
                }
            }
        }
        return 0;
    }

    /**
     * 装备ICON取装备数据
     */
    public Equip getEquipByIcon(short icon) {
        String name = EquipDataPool.getNameByIcon(icon);
        return EquipDataPool.getByName(name);

    }

    /**
     * 取装备的基础属性
     */
    public NutMap getRoleEquipBaiscInfo(RoleEquip roleEquip) {
        NutMap nutMap = new NutMap();
        FiedValue fiedValue = roleEquip.getFields().get((short) 1).getField().get((short) 205);
        if (fiedValue != null) {
            nutMap.setv("level", attrService.getValue(fiedValue.getValue()));
        }
        fiedValue = roleEquip.getFields().get((short) 1).getField().get((short) 31);
        if (fiedValue != null) {
            nutMap.setv("level1", attrService.getValue(fiedValue.getValue()));
        }
        fiedValue = roleEquip.getFields().get((short) 1).getField().get((short) 202);
        if (fiedValue != null) {
            nutMap.setv("pos", attrService.getValue(fiedValue.getValue()));
        } else {
            nutMap.setv("pos", 1);
        }
        fiedValue = roleEquip.getFields().get((short) 1).getField().get((short) 203);
        if (fiedValue != null) {
            nutMap.setv("count", attrService.getValue(fiedValue.getValue()));
        } else {
            nutMap.setv("count", 1);
        }
        fiedValue = roleEquip.getFields().get((short) 1).getField().get((short) 270);
        if (fiedValue != null) {
            nutMap.setv("limit", attrService.getValue(fiedValue.getValue()));
        }
        fiedValue = roleEquip.getFields().get((short) 1).getField().get((short) 268);
        if (fiedValue != null) {
            nutMap.setv("xiangxin", attrService.getValue(fiedValue.getValue()));
        } else {
            nutMap.setv("xiangxin", 0);
        }
        fiedValue = roleEquip.getFields().get((short) 1).getField().get((short) 44);
        if (fiedValue != null) {
            nutMap.setv("menpaiYaoqiu", attrService.getValue(fiedValue.getValue()));
        } else {
            nutMap.setv("menpaiYaoqiu", 0);
        }
        fiedValue = roleEquip.getFields().get((short) 1).getField().get((short) 29);//性别
        if (fiedValue != null) {
            nutMap.setv("sex", attrService.getValue(fiedValue.getValue()));
        } else {
            nutMap.setv("sex", 0);
        }
        fiedValue = roleEquip.getFields().get((short) 1).getField().get((short) 202);//位置
        if (fiedValue != null) {
            nutMap.setv("peidai", attrService.getValue(fiedValue.getValue()));
        } else {
            nutMap.setv("peidai", 0);
        }
        fiedValue = roleEquip.getFields().get((short) 1).getField().get((short) 74);//物品类型
        if (fiedValue != null) {
            nutMap.setv("type", attrService.getValue(fiedValue.getValue()));//1装备
        } else {
            nutMap.setv("type", 0);
        }
        fiedValue = roleEquip.getFields().get((short) 1).getField().get((short) 197);//未鉴定
        if (fiedValue != null) {
            nutMap.setv("jiandin", attrService.getValue(fiedValue.getValue()));//1
        } else {
            nutMap.setv("jiandin", 0);
        }
        fiedValue = roleEquip.getFields().get((short) 1).getField().get((short) 899);//法宝相性
        if (fiedValue != null) {
            nutMap.setv("fabaoXiangxin", attrService.getValue(fiedValue.getValue()));//1
        } else {
            nutMap.setv("fabaoXiangxin", 0);
        }
        fiedValue = roleEquip.getFields().get((short) 1).getField().get((short) 248);//黑水晶位置
        if (fiedValue != null) {
            nutMap.setv("heishuiPos", attrService.getValue(fiedValue.getValue()));//1
        } else {
            nutMap.setv("heishuiPos", 0);
        }
        //899 法宝相性
        return nutMap;
    }

    /**
     * 获得带属性黑水晶
     *
     * @param role
     * @param isGold
     * @return
     */
    public RoleEquip getBlackCrystal(Role role, boolean isGold, RoleEquipField newEquipField, int limitNum, short pos) {
        RoleEquip roleEquip = new RoleEquip();
        roleEquip.setId(mallService.getRoleEquipId());

        roleEquip.setRoleId(role.getRoleId());
        roleEquip.setPosition(pos);
        roleEquip.setName("超级黑水晶");
        roleEquip.setType("超级黑水晶");
        roleEquip.setFields(new LinkedHashMap<>());

        RoleEquipField roleEquipField = new RoleEquipField();
        roleEquipField.setType((short) 1);
        roleEquipField.setField(new LinkedHashMap<>());
        roleEquip.getFields().put(roleEquipField.getType(), roleEquipField);
        List<FiedValue> values = new ArrayList<>();
        values.add(new FiedValue(89, ""));
        values.add(new FiedValue(205, 50));
        values.add(new FiedValue(261, 0));
        values.add(new FiedValue(206, 0));
        values.add(new FiedValue(74, 6));
        values.add(new FiedValue(34, 0));
        values.add(new FiedValue(31, 0));
        values.add(new FiedValue(40, 9040));
        values.add(new FiedValue(215, 0));
        values.add(new FiedValue(348, 0));
        values.add(new FiedValue(207, 500));
        values.add(new FiedValue(264, ""));
        values.add(new FiedValue(248, 0));
        values.add(new FiedValue(1, "超级黑水晶"));
        values.add(new FiedValue(306, String.valueOf(roleEquip.getId())));
        values.add(new FiedValue(38, 0));
        values.add(new FiedValue(209, "金色"));
        values.add(new FiedValue(84, roleEquip.getId()));
        values.add(new FiedValue(270, isGold ? 0 : -new Long(System.currentTimeMillis() / 1000 + 864000 * limitNum).intValue()));
        values.add(new FiedValue(203, 1));
        values.add(new FiedValue(41, 8));
        values.add(new FiedValue(3001, ""));
        values.add(new FiedValue(887, 0));
        values.add(new FiedValue(282, 0));
        values.forEach(value -> roleEquipField.getField().put(value.getType(), value));
        roleEquip.getFields().put(newEquipField.getType(), newEquipField);
        return roleEquip;

    }

    /**
     * 位置取装备
     */
    public RoleEquip getRoleEquipByPos(Role role, int pos) {
        Set<RoleEquip> equips = new HashSet<>(role.getEquipBox().getEquips().values());
        return equips.stream().filter(roleEquip -> roleEquip.getPosition() == pos).findFirst().orElse(null);
    }

    /**
     * 物品使用
     *
     * @param pos
     * @param useNum
     */
    public void useItem(byte pos, short useNum, IoSession session) {
        Role role = SessionUtils.getRoleBySession(session);
        int newPos = pos & 0x0FF;
        log.info("物品名称==={666666666666666666}===物品位置==={666666666666666}");
        RoleEquip roleEquip = getRoleEquipByPos(role, newPos);
        if (roleEquip == null) {
            return;
        }
        if (serverService.getServer().getId() == 10000 && !roleEquip.getName().contains("玲珑") && !roleEquip.getName().endsWith("卡")){
            MessagePusher.pushMessage(role,new RespNotifyMiscEx("跨服试道中不能使用物品"));
            return;
        }
        /**防止玩家使用wpe发包*/
        if (roleEquip.queryNum() < useNum) {
            return;
        }

        log.info("物品名称==={}===物品位置==={}", roleEquip.getName(), roleEquip.getPosition());

        if (fasionService.useFasion(roleEquip, session)) {//判断是否是时装
            log.info("使用时装==={}==={}", roleEquip.getName(), roleEquip.getPosition());
            return;
        }
        String itemName = roleEquip.getName();

        if (itemName.equals("盲盒")) {
            mangHeService.openMangHe(role);
            if (delEquipNum(role, roleEquip, 1) <= 0) {
                return;
            }
            return;
        }


        if (itemName.equals(Const.TREASURE_NORMAL_ITEM_NAME)) {
            // 产生寻宝任务
            SpringUtils.getBean(DigTreasureTaskHandler.class).useTreasureMapItem(role, Const.DIG_TREASURE_TYPE_NORMAL, roleEquip);
            return;
        }
        if (itemName.equals(Const.TREASURE_SUPER_ITEM_NAME)) {
            // 产生寻宝任务
            SpringUtils.getBean(DigTreasureTaskHandler.class).useTreasureMapItem(role, Const.DIG_TREASURE_TYPE_SUPER, roleEquip);
            return;
        }
        if (itemName.equals(Const.TREASURE_SUPER_SENIOR_ITEM_NAME)) {
            // 产生寻宝任务
            SpringUtils.getBean(DigTreasureTaskHandler.class).useTreasureMapItem(role, Const.DIG_TREASURE_TYPE_SUPER_SENIOR, roleEquip);
            return;
        }
        if (itemName.equals(Const.ZHENGDAO_ITEM_NAME)) {
            /**使用证道魂*/
            SpringUtils.getBean(ZhengDaoDianHandler.class).useZhengDaoHunItem(role, roleEquip);
            return;
        }//      gmFather.handle(player,args[1].trim());
        if (itemName.contains("元·充值卡")){
            SpringUtils.getBean(ChongZhiKaService.class).addRoleRechargeCard(role,itemName,roleEquip);
            return ;
        }



        if (itemName.equals("1元充值卡")){
            NCGmFather gmFather = new NCChongzhi();
            if (gmFather != null){
                gmFather.handle(role,"1");
                if (delEquipNum(role, roleEquip, 1) <= 0) {
                    return;
                }
                return ;
            }
        }
        if (itemName.equals("3元充值卡")){
            NCGmFather gmFather = new NCChongzhi();
            if (gmFather != null){
                gmFather.handle(role,"3");
                if (delEquipNum(role, roleEquip, 1) <= 0) {
                    return;
                }
                return ;
            }
        }
        if (itemName.equals("5元充值卡")){
            NCGmFather gmFather = new NCChongzhi();
            if (gmFather != null){
                gmFather.handle(role,"5");
                if (delEquipNum(role, roleEquip, 1) <= 0) {
                    return;
                }
                return ;
            }
        }
        if (itemName.equals("10元充值卡")){
            NCGmFather gmFather = new NCChongzhi();
            if (gmFather != null){
                gmFather.handle(role,"10");
                if (delEquipNum(role, roleEquip, 1) <= 0) {
                    return;
                }
                return ;
            }
        }
        if (itemName.equals("30元充值卡")){
            NCGmFather gmFather = new NCChongzhi();
            if (gmFather != null){
                gmFather.handle(role,"30");
                if (delEquipNum(role, roleEquip, 1) <= 0) {
                    return;
                }
                return ;
            }
        }
        if (itemName.equals("50元充值卡")){
            NCGmFather gmFather = new NCChongzhi();
            if (gmFather != null){
                gmFather.handle(role,"50");
                if (delEquipNum(role, roleEquip, 1) <= 0) {
                    return;
                }
                return ;
            }
        }
        if (itemName.equals("100元充值卡")){
            NCGmFather gmFather = new NCChongzhi();
            if (gmFather != null){
                gmFather.handle(role,"100");
                if (delEquipNum(role, roleEquip, 1) <= 0) {
                    return;
                }
                return ;
            }
        }
        if (itemName.equals("武灵值")){
            roleService.addWuling(role,100,true);
            roleService.sendUpdateWuhun(role);
            //roleService.addYinde(role, 2000,true);
            //删除叠加物品
           /// MessagePusher.pushMessage(role,new RespNotifyMiscEx("经验烟花使用成功！请在北海沙滩讯找你的年兽吧！"));
            if (delEquipNum(role, roleEquip, 1) <= 0) {
                return;
            }
            //MessagePusher.pushMessage(role,new RespNotifyMiscEx("烟花测测试测试测试测试"));
            return;
        }

        if (itemName.equals("烟花筒·盛世繁花")){
            SpringUtils.getBean(YhuaNianshouBossHandler.class).useYanHua(role,(byte)1,roleEquip);
           return;
        }
        if (itemName.equals("烟花筒·绚丽彩焰")){
            SpringUtils.getBean(YhuaNianshouBossHandler.class).useYanHua(role,(byte)2,roleEquip);
            return;
        }
        if (itemName.equals("彩凤之魂")){
            MessagePusher.pushMessage(role,new RespNotifyMiscEx("彩凤之魂不能使用，只能在坐骑上注入！！"));
            return;
        }
        // mod tao 修复头像框和聊天底框使用后不删除的bug
        if (itemName.contains("头像框")){
            NutMap doubleStatus = role.getPropsStatus();
            doubleStatus.setv("touxiangkuang",itemName);
            MessagePusher.pushMessage(role,new RespNotifyMiscEx("头像框切换成功！！"));
 //           return;
        }else if (itemName.contains("聊天底框")){
            NutMap doubleStatus = role.getPropsStatus();
            doubleStatus.setv("liaotiandikuang",itemName);
            MessagePusher.pushMessage(role,new RespNotifyMiscEx("聊天底框切换成功！！"));
//            return;
        }else if (itemName.equals("喇叭")) {
        	//喇叭使用
            //打开喇叭面板 使用后减少数量
            RespGeneralNotify respGeneralNotify = new RespGeneralNotify();
            respGeneralNotify.setNotify((short) NotifyModules.NOTIFY_OPEN_DLG); //打开对话框
            respGeneralNotify.setValue("HornDlg");
            MessagePusher.pushMessage(session, respGeneralNotify);
            return;
        }
        if (itemName.equals("冥海霞光")) {
            SpringUtils.getBean(HunQiaoService.class).chouYiCi(role,roleEquip);
                return;
        }

        if (itemName.equals("精怪诱饵")) {
            RespAutoWalk respAutoWalk = new RespAutoWalk();
            respAutoWalk.setTaskName("");
            respAutoWalk.setDest("#P玉真子|E=召唤精怪#P");
            MessagePusher.pushMessage(session, respAutoWalk);
            return;
        }
        if (itemName.equals(Const.QINAG_DAO_LING_SHANG_LING_ITEM_NAME)) {
            RespQuickUseItem respQuickUseItem = new RespQuickUseItem((short) newPos, (short) pointItemService.getDouble(role), pointItemService.getPointStatus(role, PointItem.DOUBLE), (short) pointItemService.getChongFengSan(role), pointItemService.getPointStatus(role, PointItem.CHONG_FENG_SAN));
            MessagePusher.pushMessage(role, respQuickUseItem);
            return;
        }

        if (SpringUtils.getBean(CangBaoXiangHandler.class).isBox(itemName)) {
            SpringUtils.getBean(CangBaoXiangHandler.class).useBox(role, itemName);
            return;
        }

        if (SpringUtils.getBean(CangBaoXiangHandler.class).isBoxKey(itemName)) {
            SpringUtils.getBean(CangBaoXiangHandler.class).useBoxKey(role, roleEquip);
            return;
        }

        if (SpringUtils.getBean(DropService.class).isDropItem(itemName)) {
            ActivityType item_drop = null;
            if("钥匙串".equals(itemName)){
                item_drop = ActivityType.item_drop_yaoshichuan;
            }else if("银钥匙".equals(itemName)){
                item_drop = ActivityType.item_drop_yinyaoshi;
            }else if("金钥匙".equals(itemName)){
                item_drop = ActivityType.item_drop_jinyaoshi;
            }else if("水晶钥匙".equals(itemName)){
                item_drop = ActivityType.item_drop_shuijingyaoshi;
            }else if("吉祥如意".equals(itemName)){
                item_drop = ActivityType.item_drop_jixiang;
            }else if("金玉满堂".equals(itemName)){
                item_drop = ActivityType.item_drop_jinyu;
            }else if("道行盛典礼包".equals(itemName)){
                item_drop = ActivityType.item_drop_dao_shengdian;
            }
            if ( SpringUtils.getActivityService().getRemainCount(role, item_drop) <= 0) {
                MessagePusher.pushMessage(role,new RespMsg(MessageFormat.format("{0}使用已达每日上限!!",itemName)));
                return;
            }
            DropService dropService = SpringUtils.getBean(DropService.class);
            /**使用掉落道具时，判断下包裹空间是否足够 */
            for (int i=0;i<useNum;i++){
                List<FightDropSet> itemDropSet = dropService.getItemDropSet(itemName);
                SpringUtils.getBean(FightService.class).forDropSet(role,itemDropSet,itemName);
                int activityCount = role.getActivity().getFinishCounts().getInt(item_drop.getActivityId(), 0);
                int count = activityCount + 1;
                role.getActivity().getFinishCounts().put(item_drop.getActivityId(), count);
               // dropService.addDropLimit(role, itemName, 1);
                //一个个删除
                if (delEquipNum(role, roleEquip, 1) <= 0) {
                    continue;
                }
            }
        }else {
            if(DataCache.GIFT_BAG_DATA_MAP.containsKey(itemName) || "九转仙灵露·人物".equals(itemName)  || "九转仙灵露·宠物".equals(itemName) || DataCache.USE_BAG_DATA_MAP.containsKey(itemName) || "成品天书礼包".equals(itemName)){

            }else{
                //删除叠加物品
                if (delEquipNum(role, roleEquip, useNum) <= 0) {
                    return;
                }
            }
        }


        if (itemName.endsWith("卡")){
            SpringUtils.getBean(ChangeCardService.class).getChangeCard(role,itemName);
            return;
        }
        /**刷新背包*/
        RespFinishSortPack respFinishSortPack = new RespFinishSortPack();
        MessagePusher.pushMessage(session, respFinishSortPack);
        RespFlushPack respFlushPack = new RespFlushPack();
        respFlushPack.setType("bag");
        MessagePusher.pushMessage(session, respFlushPack);

        // 处理礼包信息
        if (DataCache.GIFT_BAG_DATA_MAP.containsKey(itemName)) {
            List<GiftBagData> giftBagDataList = DataCache.GIFT_BAG_DATA_MAP.get(itemName);
            if (giftBagDataList.size() == 0) {
                MessagePusher.pushMessage(session, new RespNotifyMiscEx("礼包#R" + itemName + "#n未进行配置"));
                return;
            }
            for (GiftBagData giftBagData : giftBagDataList) {
                GiftHelper.INSTANCE.getGiftHelper(giftBagData.getType()).getReward(role, giftBagData);
            }
        }  // 处理信使用药品息
        if (DataCache.USE_BAG_DATA_MAP.containsKey(itemName)) {
            SpringUtils.getBean(NewNpcService.class).addRolePolorPoint(role,roleEquip);
        }else if (itemName.contains("灵池")) {
            int addSavaFali;
            if (itemName.contains("高")) {
                addSavaFali = 7500000 * useNum;
            } else if (itemName.contains("中")) {
                addSavaFali = 1500000 * useNum;
            } else {
                addSavaFali = 300000 * useNum;
            }

            int saveFali = role.getSaveMana();
            saveFali = saveFali + addSavaFali;
            if (saveFali > 900000000) {
                saveFali = 900000000;
            }
            role.setSaveMana(saveFali);
            role.setCurrMana(role.getMaxMana());
            roleService.sendExtraAttribute(role);
            role.save();
            MessagePusher.pushMessage(session, new RespNotifyMiscEx("你使用了#R" + useNum + "#n个#R" + roleEquip.getName() + "#n，法力储备增加了#R" + addSavaFali + "#n点。"));
        } else if (itemName.contains("血池")) {
            int addSavaQixue;
            if (itemName.contains("高")) {
                addSavaQixue = 7500000 * useNum;
            } else if (itemName.contains("中")) {
                addSavaQixue = 1500000 * useNum;
            } else {
                addSavaQixue = 300000 * useNum;
            }

            int saveQixue = role.getSaveLife();
            saveQixue = saveQixue + addSavaQixue;
            if (saveQixue > 900000000) {
                saveQixue = 900000000;
            }
            role.setSaveLife(saveQixue);
            role.setCurrLife(role.getMaxLife());
            roleService.sendExtraAttribute(role);
            role.save();
            MessagePusher.pushMessage(session, new RespNotifyMiscEx("你使用了#R" + useNum + "#n个#R" + roleEquip.getName() + "#n，气血储备增加了#R" + addSavaQixue + "#n点。"));
        } else if (itemName.equals("灵物囊")) {//其他物品
//            short space = SpringUtils.getBean(BagService.class).getPos(role, false);
//            if (space < 0) {
//                MessagePusher.pushMessage(role, new RespMsg("你的包裹已满，还是整理后再来吧。"));
//                return;
//            }

            OnlineMall onlineMall = new OnlineMall();
            boolean isGold = true;
            if (attrService.getValue(roleEquip.getFields().get((short) 1).getField().get((short) 270).getValue()) == 2) {
                isGold = false;
            }

            String[] names = {"困灵砂", "拘首环", "控心玉", "定鞍石", "驱力刺"};
            Random random = new Random();
            int index = random.nextInt(names.length);
            onlineMall.setName(names[index]);
            onlineMall.setItemtype((short) 10);

            bagService.addRoleEquip(role, isGold, 1, onlineMall);
            MessagePusher.pushMessage(session, new RespIconCartoon(names[index]));

        } else if (itemName.equals("宠风散")) {
            NutMap doubleStatus = role.getPropsStatus();
            int petDouble = doubleStatus.getInt("pet", 0);
            petDouble += 200 * useNum;
            if(petDouble>=PointItem.CHONG_FENG_SAN.getMax()){
                petDouble=PointItem.CHONG_FENG_SAN.getMax();
            }else if(petDouble<0){
                petDouble=0;
            }
            doubleStatus.setv("pet", petDouble);
            role.save();

//            ArrayList<FiedValue> list = new ArrayList<>();
//            FiedValue fiedValue = new FiedValue();
//            fiedValue.setType((short) 3002);
//            fiedValue.setVT((byte) 3);
//            fiedValue.setValue(doubleStatus.getInt("pet"));
//            list.add(fiedValue);
//            RespUpdate respUpdate = new RespUpdate();
//            respUpdate.setRoleId(role.getRoleId());
//            respUpdate.setList(list);
//            MessagePusher.pushMessage(session, respUpdate);
            roleService.refreshRoleBasic(role);

            MessagePusher.pushMessage(session, new RespNotifyMiscEx("你使用了#R" + useNum + "#n个#R" + roleEquip.getName() + "#n，当前剩余#R" + doubleStatus.getInt("pet") + "#n点。"));
        } else if (itemName.equals("超级仙风散")) {
            NutMap doubleStatus = role.getPropsStatus();
            int roleDouble = doubleStatus.getInt("role", 0);
            roleDouble += 200 * useNum;
            if(roleDouble>=PointItem.DOUBLE.getMax()){
                roleDouble=PointItem.DOUBLE.getMax();
            }else if(roleDouble<0){
                roleDouble=0;
            }
            doubleStatus.setv("role", roleDouble);
            role.save();

//            ArrayList<FiedValue> list = new ArrayList<>();
//            FiedValue fiedValue = new FiedValue();
//            fiedValue.setType((short) 191);
//            fiedValue.setVT((byte) 2);
//            fiedValue.setValue((short) doubleStatus.getInt("role"));
//            list.add(fiedValue);
//            RespUpdate respUpdate = new RespUpdate();
//            respUpdate.setRoleId(role.getRoleId());
//            respUpdate.setList(list);
//            MessagePusher.pushMessage(session, respUpdate);
            roleService.refreshRoleBasic(role);
            MessagePusher.pushMessage(session, new RespNotifyMiscEx("你使用了#R" + useNum + "#n个#R" + roleEquip.getName() + "#n，当前剩余#R" + doubleStatus.getInt("role") + "#n点。"));
        } else if (itemName.equals("高级驯兽诀")) {
            role.setSaveLoyalty(role.getSaveLoyalty() + 2500 * useNum);
            ArrayList<FiedValue> list = new ArrayList<>();
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 178);
            fiedValue.setVT((byte) 3);
            fiedValue.setValue(role.getSaveLoyalty());
            list.add(fiedValue);
            RespUpdate respUpdate = new RespUpdate();
            respUpdate.setRoleId(role.getRoleId());
            respUpdate.setList(list);
            MessagePusher.pushMessage(session, respUpdate);
            role.save();
            MessagePusher.pushMessage(session, new RespNotifyMiscEx("你使用了#R" + useNum + "#n个#R高级驯兽诀#n，忠诚储备增加了#R" + 2500 * useNum + "#n点。"));
        } else if (itemName.equals("神木鼎")) {
            NutMap doubleStatus = role.getPropsStatus();
            int shenmu = doubleStatus.getInt("shenmu", 0);
            shenmu += 1000 * useNum;
            if(shenmu>=12000){
                shenmu=12000;
            }else if(shenmu<0){
                shenmu=0;
            }
            doubleStatus.setv("shenmu", shenmu);
            role.save();

//            ArrayList<FiedValue> list = new ArrayList<>();
//            FiedValue fiedValue = new FiedValue();
//            fiedValue.setType((short) 875);
//            fiedValue.setVT((byte) 2);
//            fiedValue.setValue((short) doubleStatus.getInt("shenmu"));
//            list.add(fiedValue);
//            RespUpdate respUpdate = new RespUpdate();
//            respUpdate.setRoleId(role.getRoleId());
//            respUpdate.setList(list);
//            MessagePusher.pushMessage(session, respUpdate);
            roleService.refreshRoleBasic(role);
            MessagePusher.pushMessage(session, new RespNotifyMiscEx("你使用了#R" + useNum + "#n个#R" + roleEquip.getName() + "#n，当前剩余#R" + doubleStatus.getInt("shenmu") + "#n点。"));
        } else if (itemName.equals("紫气鸿蒙")) {
            NutMap doubleStatus = role.getPropsStatus();
            int ziqi = doubleStatus.getInt("ziqi", 0);
            ziqi += 200 * useNum;
            if(ziqi>=PointItem.ZI_QI_HONG_MENG.getMax()){
                ziqi=PointItem.ZI_QI_HONG_MENG.getMax();
            }else if(ziqi<0){
                ziqi=0;
            }
            doubleStatus.setv("ziqi", ziqi);
            role.save();

//            ArrayList<FiedValue> list = new ArrayList<>();
//            FiedValue fiedValue = new FiedValue();
//            fiedValue.setType((short) 900);
//            fiedValue.setVT((byte) 3);
//            fiedValue.setValue((short) doubleStatus.getInt("ziqi"));
//            list.add(fiedValue);
//            RespUpdate respUpdate = new RespUpdate();
//            respUpdate.setRoleId(role.getRoleId());
//            respUpdate.setList(list);
//            MessagePusher.pushMessage(session, respUpdate);
            roleService.refreshRoleBasic(role);
            MessagePusher.pushMessage(session, new RespNotifyMiscEx("你使用了#R" + useNum + "#n个#R" + roleEquip.getName() + "#n，当前剩余#R" + doubleStatus.getInt("ziqi") + "#n点。"));
        }else if (itemName.equals("急急如律令")) {
            NutMap doubleStatus = role.getPropsStatus();
            int ziqi = doubleStatus.getInt("manguai", 0);
            ziqi += 200 * useNum;
            if(ziqi>=PointItem.JI_JI_RU_LV_LING.getMax()){
                ziqi=PointItem.JI_JI_RU_LV_LING.getMax();
            }else if(ziqi<0){
                ziqi=0;
            }
            doubleStatus.setv("manguai", ziqi);
            role.save();

            ArrayList<FiedValue> list = new ArrayList<>();
            FiedValue fiedValue = new FiedValue();
            fiedValue.setType((short) 312);
            fiedValue.setVT((byte) 3);
            fiedValue.setValue((short) doubleStatus.getInt("manguai"));
            list.add(fiedValue);
            RespUpdate respUpdate = new RespUpdate();
            respUpdate.setRoleId(role.getRoleId());
            respUpdate.setList(list);
            MessagePusher.pushMessage(session, respUpdate);
            MessagePusher.pushMessage(session, new RespNotifyMiscEx("你使用了#R" + useNum + "#n个#R" + roleEquip.getName() + "#n，当前剩余#R" + doubleStatus.getInt("manguai") + "#n点。"));
        } else if (itemName.equals("天书")) {
 //           short space = SpringUtils.getBean(BagService.class).getPos(role, false);
 //           if (space < 0) {
//                MessagePusher.pushMessage(role, new RespMsg("你的包裹已满，还是整理后再来吧。"));
 //               return;
 //           }

            OnlineMall onlineMall = new OnlineMall();
            boolean isGold = true;
            if (attrService.getValue(roleEquip.getFields().get((short) 1).getField().get((short) 270).getValue()) == 2) {
                isGold = false;
            }

            Random random = new Random();//使用天书 获得已使用天书
            int index = random.nextInt(names.length);
            onlineMall.setName(names[index]);
            onlineMall.setItemtype((short) 13);
            onlineMall.setType(16518);

            bagService.addRoleEquip(role, isGold, 1, onlineMall);
            MessagePusher.pushMessage(session, new RespIconCartoon(names[index]));
        }  else if (itemName.equals("金色天书")) {
            OnlineMall onlineMall = new OnlineMall();
            boolean isGold = true;
            if (attrService.getValue(roleEquip.getFields().get((short) 1).getField().get((short) 270).getValue()) == 2) {
                isGold = false;
            }
            Random random = new Random();//使用天书 获得已使用天书
            int index = random.nextInt(superNames.length);
            onlineMall.setName(superNames[index]);
            onlineMall.setItemtype((short) 13);
            onlineMall.setType(16518);
            bagService.addRoleEquip(role, isGold, 1, onlineMall);
            MessagePusher.pushMessage(session, new RespIconCartoon(superNames[index]));
        }  else if (itemName.equals("成品天书礼包")) {
            SpringUtils.getBean(NewNpcService.class).getBookContent(role);
        }  else if (itemName.equals("新手装备礼包")) {
            SpringUtils.getBean(EquipProduceHandler.class).getEquip(role, "力套",70);
            SpringUtils.getBean(EquipProduceHandler.class).getEquip(role,"法套",70);
        }else if (itemName.equals("五行合缘露")) {//洗相性
            RoleAttribMonitor roleAttribMonitor = new RoleAttribMonitor(role);

            short total = 0;
            if (role.getMetal() >= 1) {//金
                role.setMetal((short) (role.getMetal() - 1));
                total++;
            }
            if (role.getWood() >= 1) {//木
                role.setWood((short) (role.getWood() - 1));
                total++;
            }
            if (role.getWater() >= 1) {//水
                role.setWater((short) (role.getWater() - 1));
                total++;
            }
            if (role.getFire() >= 1) {//火
                role.setFire((short) (role.getFire() - 1));
                total++;
            }
            if (role.getEarth() >= 1) {//土
                role.setEarth((short) (role.getEarth() - 1));
                total++;
            }
            role.setLastPolar(roleService.getLastPolarPoint(role));
            MessagePusher.pushMessage(session, new RespNotifyMiscEx("恭喜你，成功洗去了#R" + total + "#n相性点。"));

            roleService.sendExtraAttribute(role);
            role.save();
            roleAttribMonitor.end();
        } else if (itemName.equals("易经洗髓丹")) {//洗属性
            RoleAttribMonitor roleAttribMonitor = new RoleAttribMonitor(role);

            short total = 0;
            if (role.getCon() >= 2) {//体质
                role.setCon((short) (role.getCon() - 2));
                total += 2;
            }
            if (role.getStr() >= 2) {//力量
                role.setStr((short) (role.getStr() - 2));
                total += 2;
            }
            if (role.getWiz() >= 2) {//灵力
                role.setWiz((short) (role.getWiz() - 2));
                total += 2;
            }
            if (role.getDex() >= 2) {//敏捷
                role.setDex((short) (role.getDex() - 2));
                total += 2;
            }
            role.setLastAttrib(roleService.getLastAttributePoint(role));
            MessagePusher.pushMessage(session, new RespNotifyMiscEx("恭喜你，成功洗去了#R" + total + "#n属性点。"));

            roleService.sendExtraAttribute(role);
            role.save();
            roleAttribMonitor.end();
        } else if (itemName.equals("天神护佑")) {
            role.setNoDeath((short) (role.getNoDeath() + 1));
            role.save();

            SpringUtils.getBean(GodProtectTaskHandler.class).acceptTask(role);
        }else if (itemName.equals("烟花筒·绚丽彩焰")) {
            //烟花特效 todo

            role.save();

        }
        else if (itemName.equals("铸灵石")) {
            //铸灵石 todo

            role.save();

        }

        else if (itemName.equals("九转仙灵露·宠物")) {
            //铸灵石 todo
            SpringUtils.getBean(NewNpcService.class).addPetAttribPoint(role,roleEquip);
        }
        else if (itemName.equals("九转仙灵露·人物")) {
            //铸灵石 todo
            SpringUtils.getBean(NewNpcService.class).getAttribPointContent(role);
        }
        else if (itemName.contains("情缘盒")) {
            OnlineMall onlineMall = new OnlineMall();
            boolean isGold = true;
            if (this.attrService.getValue(((FiedValue) ((RoleEquipField) roleEquip.getFields().get(Short.valueOf((short) 1))).getField().get(Short.valueOf((short) 270))).getValue()).intValue() == 2) {
                isGold = false;
            }
            String[] names = new String[2];
            names[0] = "百合";
            if (role.getGender() == 1) {
                names[1] = "百合";
            } else {
                names[1] = "百合";
            }
            Random random = new Random();
            for (int i = 0; i < 3; i++) {
                int index = random.nextInt(names.length);
                onlineMall.setName(names[index]);
                onlineMall.setItemtype((short) 2);
                this.bagService.addRoleEquip(role, isGold, 1, onlineMall);
                MessagePusher.pushMessage(session, (Message) new RespIconCartoon(names[index]));
            }
        }

        respFinishSortPack = new RespFinishSortPack();
        respFinishSortPack.setStart_range((byte) 0);
        MessagePusher.pushMessage(session, respFinishSortPack);
    }

    /**
     * 添加物品飞行器
     */
    public void addMall(String name, boolean isGold, Role role, int num) {
        OnlineMall onlineMall = DataCache.NAME_MALL.get(name);
        if (onlineMall == null ) {
            int type = FlyTypeEnums.getType(name);
            if(type>0){
                onlineMall = new OnlineMall();
                onlineMall.setName(name);
                onlineMall.setItemtype((short) 34);
                onlineMall.setType(260);
            }else{
                onlineMall = new OnlineMall();
                onlineMall.setName(name);
                onlineMall.setItemtype((short) 10);
                onlineMall.setType(260);
            }


        }
        if(name!=null && name.contains("梦荷")){
            isGold = true ;
        }

        bagService.addRoleEquip(role, isGold, num, onlineMall);
        MessagePusher.pushMessage(role, new RespIconCartoon(name));

        String itemUnit = getItemUnit(name);
        String msg = MessageFormat.format("你获得了#R{0}#n{1}#R{2}#n。", num, itemUnit, name);
        MessagePusher.pushMessage(role, new RespNotifyMiscEx(msg));
    }

    public void addMall(String name, boolean isGold, Role role) {
        OnlineMall onlineMall = DataCache.NAME_MALL.get(name);
        if (onlineMall == null) {
            onlineMall = new OnlineMall();
            onlineMall.setName(name);
            onlineMall.setItemtype((short) 10);
            onlineMall.setType(260);
        }
        bagService.addRoleEquip(role, isGold, 1, onlineMall);
        MessagePusher.pushMessage(role, new RespIconCartoon(name));
    }

    public void addMall(ChoujiangGift choujiangGift, boolean isGold, Role role) {
        OnlineMall onlineMall = DataCache.NAME_MALL.get(choujiangGift.getName());
        if (onlineMall == null) {
            onlineMall = new OnlineMall();
            onlineMall.setName(choujiangGift.getName());
            onlineMall.setItemtype((short) choujiangGift.getGoodType());
            onlineMall.setType(choujiangGift.getUseType());
        }
        bagService.addRoleEquip(role, isGold, 1, onlineMall);
        MessagePusher.pushMessage(role, new RespIconCartoon(choujiangGift.getName()));
    }


    /**
     * 出售物品toNpc
     */
    public void soldToSystem(Role role, short pos, short num) {
        if (num <= 0) {
            return;
        }
        RoleEquip roleEquip = getRoleEquipByPos(role, pos);
        if (roleEquip == null) {
            return;
        }

        int price = (roleEquip.queryPrice() / 5) * num;
        if (price < 0) {
            return;
        }
        boolean isLimit = roleEquip.isLimit();
        if (!isLimit) {
            if (role.getMoney() + price >= 2000000000) {
                return;
            }
        } else {
            if (role.getVoucher() + price >= 2000000000) {
                return;
            }
        }
        int count = roleEquip.queryNum();
        if (count < num) {
            return;
        }
        String equipType = roleEquip.getType();
        if (equipType.equals("装备") || equipType.equals("高级首饰") || equipType.equals("法宝") || equipType.equals("超级黑水晶·")) {
            delRoleEquip(roleEquip, role);
        } else {
            if (count <= num) {
                // 删除物品
                delRoleEquip(roleEquip, role);
            } else {
                if (delEquipNum(role, roleEquip, num) != num) {
                    return;
                }
            }
        }

        if (isLimit) {
            role.setVoucher(role.getVoucher() + price);
            RespIconCartoon respIconCartoon = new RespIconCartoon();
            respIconCartoon.setType((short) 3);
            respIconCartoon.setName("代金券");
            respIconCartoon.setParam(String.valueOf(price));
            MessagePusher.pushMessage(role, respIconCartoon);
        } else {
            roleService.addMoney(role, price, Reason.SALE_ITEM);
            RespIconCartoon respIconCartoon = new RespIconCartoon();
            respIconCartoon.setType((short) 7);
            respIconCartoon.setName("金钱");
            respIconCartoon.setParam(String.valueOf(price));
            MessagePusher.pushMessage(role, respIconCartoon);
        }
        SpecialItem specialItem = mallService.getSpecialItem(roleEquip.getName());
        String unit = "个";
        if (specialItem != null) {
            unit = specialItem.getUnit() != null ? specialItem.getUnit() : unit;
        }
        String message = "你成功出售#R" + num + "#n" + (unit != null ? unit : "个") + "#R" + roleEquip.getName() + "#n获得" + AsktaoUtil.getMoneyFormat(price) + "文" + (isLimit ? "代金券" : "金钱") + "#n。";
        MessagePusher.pushMessage(role, new RespNotifyMiscEx(message));
        roleService.updateRoleMoney(role);
        role.save();
    }


    /**
     * 增加装备限制时间
     */
    public void addRoleEquipLimitTimeDay(RoleEquip roleEquip, int limitNum) {
        FiedValue fiedValue = roleEquip.getFields().get((short) 1).getField().get((short) 270);
        if (fiedValue != null && limitNum > 0) {
            int value = attrService.getValue(fiedValue.getValue());
            int currTime = new Long(System.currentTimeMillis() / 1000).intValue();
            if (value == 0) {
                value = currTime;
                fiedValue.setValue(-(value + 86400 * limitNum));// 增加限制天数
            } else {
                if (-value + 86400 * limitNum >= currTime + 864000 * 6) {
                    fiedValue.setValue(-(currTime + 864000 * 6));// 增加限制天数
                } else {
                    fiedValue.setValue(value - 86400 * limitNum);// 增加限制天数
                }
            }
        }
    }

    /**
     * 装备转换性别
     *
     * @param roleEquip
     * @return
     */
    public void changeEquipSex(RoleEquip roleEquip) {
        Equip equip = EquipDataPool.getByName(roleEquip.getName());
        List<String> arrayList = EquipDataPool.getNamesBy(equip.getReq_level(), equip.getPosition());
        if (arrayList.isEmpty()) {
            return;
        }
        for (String string : arrayList) {
            if (!string.equals(roleEquip.getName())) {
                Equip newEquip = EquipDataPool.getByName(string);
                if (newEquip != null) {
                    roleEquip.setName(newEquip.getKey_name());
                    roleEquip.getFields().get((short) 1).getField().get((short) 40).setValue((short) newEquip.getIcon());
                    roleEquip.getFields().get((short) 1).getField().get((short) 1).setValue(newEquip.getKey_name());
                    roleEquip.getFields().get((short) 1).getField().get((short) 29).setValue(newEquip.getGender());
                    break;
                }
            }
        }
    }

    /**
     * 鉴定获得宝石
     */
    public RoleEquip identityGem(Role role, String name, short newPos, int addNum) {
        OnlineMall onlineMall = new OnlineMall();
        onlineMall.setName(name);
        onlineMall.setItemtype((short) 5);
        onlineMall.setType(6);

        SpecialItem specialItem = mallService.getSpecialItem(onlineMall.getName());
        if (specialItem == null) {
            specialItem = new SpecialItem();
            Medicine medicine = ShopDataPool.getMedicineBy(onlineMall.getName());
            if (medicine != null) {
                specialItem.setIcon(medicine.getIcon());
            } else {
                specialItem.setIcon(9500);
            }
        }
        if (Strings.isEmpty(specialItem.getColor())) {
            specialItem.setColor("金色");
        }

        for (Map.Entry<Integer, RoleEquip> entry : role.getEquipBox().getEquips().entrySet()) {
            RoleEquip oldEquip = entry.getValue();
            if (oldEquip == null || oldEquip.getPosition() > 165 || oldEquip.getPosition() < 41) {
                continue;
            }
            if (oldEquip.getName().equals(name)) {//已有相同未鉴定装备 直接叠加
                addNum = bagService.mergeItem(role, oldEquip, 99, addNum);
                if (addNum <= 0) {
                    return oldEquip;
                }
            }
        }
        RoleEquip newEquip = new RoleEquip();
        newEquip.setId(mallService.getRoleEquipId());

        newEquip.setRoleId(role.getRoleId());
        newEquip.setPosition(newPos);
        newEquip.setName(onlineMall.getName());
        newEquip.setFields(new LinkedHashMap<>());
        {
            RoleEquipField roleEquipField = new RoleEquipField();
            roleEquipField.setType((short) 1);
            roleEquipField.setField(new LinkedHashMap<>());
            newEquip.getFields().put(roleEquipField.getType(), roleEquipField);
            {
                FiedValue fiedValue = new FiedValue();
                fiedValue.setType((short) 205);//
                fiedValue.setVT((byte) 6);
                fiedValue.setValue((byte) 50);
                roleEquipField.getField().put(fiedValue.getType(), fiedValue);
            }
            {
                FiedValue fiedValue = new FiedValue();
                fiedValue.setType((short) 203);//
                fiedValue.setVT((byte) 2);
                fiedValue.setValue((byte) addNum);
                roleEquipField.getField().put(fiedValue.getType(), fiedValue);
            }
            {
                FiedValue fiedValue = new FiedValue();
                fiedValue.setType((short) 206);//使用方式
                fiedValue.setVT((byte) 3);
                fiedValue.setValue(onlineMall.getType());
                roleEquipField.getField().put(fiedValue.getType(), fiedValue);
            }
            {
                FiedValue fiedValue = new FiedValue();
                fiedValue.setType((short) 74);//物品类型
                fiedValue.setVT((byte) 7);
                fiedValue.setValue(onlineMall.getItemtype());
                roleEquipField.getField().put(fiedValue.getType(), fiedValue);
            }
            {
                FiedValue fiedValue = new FiedValue();
                fiedValue.setType((short) 40);// 背包中的图标
                fiedValue.setVT((byte) 7);
                fiedValue.setValue((short) specialItem.getIcon());
                roleEquipField.getField().put(fiedValue.getType(), fiedValue);
            }
            {
                FiedValue fiedValue = new FiedValue();
                fiedValue.setType((short) 207);//出售价格
                fiedValue.setVT((byte) 3);
                fiedValue.setValue((short) 250);
                roleEquipField.getField().put(fiedValue.getType(), fiedValue);
            }
            {
                FiedValue fiedValue = new FiedValue();
                fiedValue.setType((short) 1);//名称
                fiedValue.setVT((byte) 4);
                fiedValue.setValue(onlineMall.getName());
                roleEquipField.getField().put(fiedValue.getType(), fiedValue);
            }
            {
                FiedValue fiedValue = new FiedValue();
                fiedValue.setType((short) 306);
                fiedValue.setVT((byte) 4);
                fiedValue.setValue(newEquip.getId() + "");//"5933997D5DCD40014D01"
                roleEquipField.getField().put(fiedValue.getType(), fiedValue);
            }
            {
                FiedValue fiedValue = new FiedValue();
                fiedValue.setType((short) 209);
                fiedValue.setVT((byte) 4);
                fiedValue.setValue("");
                roleEquipField.getField().put(fiedValue.getType(), fiedValue);
            }
            {
                FiedValue fiedValue = new FiedValue();
                fiedValue.setType((short) 84);
                fiedValue.setVT((byte) 3);
                fiedValue.setValue(newEquip.getId());
                roleEquipField.getField().put(fiedValue.getType(), fiedValue);
            }
            {
                FiedValue fiedValue = new FiedValue();
                fiedValue.setType((short) 203);// 叠加数量
                fiedValue.setVT((byte) 2);
                fiedValue.setValue((short) 1);
                roleEquipField.getField().put(fiedValue.getType(), fiedValue);
            }
            {
                FiedValue fiedValue = new FiedValue();
                fiedValue.setType((short) 887);
                fiedValue.setVT((byte) 3);
                fiedValue.setValue(0);
                roleEquipField.getField().put(fiedValue.getType(), fiedValue);
            }
            {
                FiedValue fiedValue = new FiedValue();
                fiedValue.setType((short) 282);
                fiedValue.setVT((byte) 2);
                fiedValue.setValue(2);
                roleEquipField.getField().put(fiedValue.getType(), fiedValue);
            }
            {
                FiedValue fiedValue = new FiedValue();
                fiedValue.setType((short) 270);
                fiedValue.setVT((byte) 3);
                fiedValue.setValue(0);
                roleEquipField.getField().put(fiedValue.getType(), fiedValue);
            }
        }
        newEquip.setType("装备道具");
        add(role, newEquip);
        return newEquip;
    }

    /**
     * 鉴定装备
     *
     * @return
     */
    public RoleEquip identifyEquip(Role role, String equipName, short newPos, boolean isFullField) {
        RoleEquip roleEquip = new RoleEquip();
        roleEquip.setType("装备");

        Equip equip = EquipDataPool.getByName(equipName);
        int id = mallService.getRoleEquipId();
        roleEquip.setId(id);

        roleEquip.setName(equipName);
        roleEquip.setRoleId(role.getRoleId());
        roleEquip.setPosition(newPos);
        int shuxingNum = (int) Math.round((Math.random() * 4) + 1);

        {
            RoleEquipField roleEquipField = new RoleEquipField();
            roleEquipField.setType((short) 1);
            String color = "";
            if (shuxingNum <= 3) {
                color = "蓝色";
            } else {
                color = "金色";
            }
            LinkedHashMap<Short, FiedValue> linkedHashMap = getBasicAttrNew(equip, roleEquip, color, true);
            roleEquipField.setField(linkedHashMap);
            roleEquip.getFields().put(roleEquipField.getType(), roleEquipField);
            RoleEquipField roleEquipField1 = getBasicAttNew(equip);
            roleEquip.getFields().put(roleEquipField1.getType(), roleEquipField1);
        }

        byte pos = equip.getPosition();
        Set<Integer> strings = new HashSet<>();
        int result = 0;
        int temp = shuxingNum;
        if (temp > 3) {
            temp = 3;
        }
        do {
            result = getRandomFieldId(pos);
            if (!strings.contains(result)) {
                strings.add(result);
                if (strings.size() >= temp) {
                    break;
                }
            }
        } while (true);
        int pink = 0;
        if (shuxingNum >= 4) {
            pink = getRandomFieldId(pos);
        }
        int gold = 0;
        if (shuxingNum == 5) {
            do {
                gold = getRandomFieldId(pos);
            } while (gold == pink);
        }

        Random random = new Random();
        //蓝色属性  根据属性条数来添加蓝色属性
        {
            RoleEquipField roleEquipField = new RoleEquipField();
            roleEquipField.setType((short) 514);
            LinkedHashMap<Short, FiedValue> linkedHashMap1 = new LinkedHashMap<>();
            for (Integer fieldId : strings) {
                FiedValue fiedValue = new FiedValue();
                fiedValue.setType(fieldId);
                Attribute attribute = attrService.getAttr(fieldId);
                fiedValue.setVT(attribute.getType());

                int min = attrService.getFiledMin(fieldId, equip.getReq_level(), pos);
                int max = attrService.getFiledMax(fieldId, equip.getReq_level(), pos);
                int value = random.nextInt(max - min) + min + 1;
                if (isFullField) {
                    isFullField = false;
                    value = max;
                }
                fiedValue.setValue(value);
                linkedHashMap1.put(fiedValue.getType(), fiedValue);
                numorIdenfity(role, equip, attribute, max, value);
            }
            roleEquipField.setField(linkedHashMap1);
            roleEquip.getFields().put(roleEquipField.getType(), roleEquipField);
        }
        // 粉色属性 属性条数大于等于3才写入
        if (shuxingNum >= 4) {
            RoleEquipField equipField = new RoleEquipField();
            equipField.setType((short) 770);
            LinkedHashMap<Short, FiedValue> linkedHashMap1 = new LinkedHashMap<>();
            {//基础气血
                FiedValue fiedValue = new FiedValue();
                fiedValue.setType((short) pink);
                Attribute attribute = attrService.getAttr((short) pink);
                fiedValue.setVT(attribute.getType());
                int min = attrService.getFiledMin(pink, equip.getReq_level(), pos);
                int max = attrService.getFiledMax(pink, equip.getReq_level(), pos);
                int value = random.nextInt(max - min) + min + 1;
                fiedValue.setValue(value);
                linkedHashMap1.put(fiedValue.getType(), fiedValue);
                numorIdenfity(role, equip, attribute, max, value);
            }
            equipField.setField(linkedHashMap1);
            roleEquip.getFields().put(equipField.getType(), equipField);
        }


        //黄色属性 属性条数大于等于4才写入
        if (shuxingNum == 5) {
            RoleEquipField roleEquipField = new RoleEquipField();
            roleEquipField.setType((short) 1026);
            LinkedHashMap<Short, FiedValue> linkedHashMap1 = new LinkedHashMap<>();
            {//基础气血
                FiedValue fiedValue = new FiedValue();
                fiedValue.setType((short) gold);
                Attribute attribute = attrService.getAttr((short) gold);
                fiedValue.setVT(attribute.getType());
                int min = attrService.getFiledMin(gold, equip.getReq_level(), pos);
                int max = attrService.getFiledMax(gold, equip.getReq_level(), pos);
                int value = random.nextInt(max - min) + min + 1;
                fiedValue.setValue(value);
                linkedHashMap1.put(fiedValue.getType(), fiedValue);
                numorIdenfity(role, equip, attribute, max, value);
            }
            roleEquipField.setField(linkedHashMap1);
            roleEquip.getFields().put(roleEquipField.getType(), roleEquipField);
        }

        refreshRoleEquip(role, roleEquip);
        add(role, roleEquip);
        return roleEquip;
    }

    /**
     * 装备鉴定满属性时发谣言消息
     */
    private void numorIdenfity(Role role, Equip equip, Attribute attribute, int max, int value) {
        if (role == null || equip == null || attribute == null) {return ;}

        if (value == max) {
            String addAttr = attribute.getValuename() + value;
            if (attrService.isPercentFieldName(attribute.getName())) {
                addAttr += "%";
            }
            String content = I18nIdDataPool.getI18nContent(I18nId.PMT_2100, role.getName(), addAttr, equip.getKey_name());
            //SpringUtils.getChatService().sendNumor(content, Const.BRODCAST_MSG_TYPE_ROLE);
        }
    }

    /**
     * 改造谣言
     */
    public void sendEquipMsg(Role role, RoleEquip roleEquip, int tempLevel, String msg) {
        String uuId = R.UU32().toUpperCase();
        String notice = String.format(msg, role.getName(), "\t" + roleEquip.getName() + "=" + uuId, tempLevel);
        broadcastService.sendRumor(notice, NutMap.NEW().setv("type", "equip").setv("equip", roleEquip).setv("uuId", uuId));
    }


    /**
     * 在装备列表中添加匹配玩家使用的装备给玩家
     *
     * @param role
     * @param equipSetList
     * @param count
     * @param isChoujiang
     * @return
     */
    public List<RoleEquip> addEquipMatchRole(Role role, List<Equip> equipSetList, int count, boolean isChoujiang) {
        /***遍历装备列表，获得匹配角色的装备*/
        List<Equip> equipListMatchRole = getEquipListMatchRole(role, equipSetList);
        List<RoleEquip> roleEquipList = new ArrayList<RoleEquip>();
        for (Equip equipSet : equipListMatchRole) {

            /**实际添加装备*/
            List<RoleEquip> roleEquips = addEquip(role, equipSet, count, isChoujiang);


            roleEquipList.addAll(roleEquips);
        }

        return roleEquipList;
    }

    /**
     * 获得匹配角色的装备列表
     */
    private List<Equip> getEquipListMatchRole(Role role, List<Equip> equipSetList) {
        List<Equip> matchEquipSets = new ArrayList<Equip>(2);
        for (Equip equipSet : equipSetList) {
            /**不匹配时，跳过*/
            if (!isEquipMatchRole(role, equipSet)) {
                continue;
            }

            matchEquipSets.add(equipSet);
        }

        /**此时列表中的都是匹配角色的装备*/
        return matchEquipSets;
    }

    /**
     * 是否匹配角色的装备
     */
    private boolean isEquipMatchRole(Role role, Equip equipSet) {
        if (equipSet.getPosition() == Const.POS_WEAPON) {
            /**武器装备需要匹配门派*/
            return equipSet.getMenpai() == role.getPolar();
        } else {
            /**其他装备需要匹配性别，等于0时表示不需要匹配*/
            return equipSet.getGender() == role.getGender() || equipSet.getGender() == 0;
        }
    }

    /**
     * 添加装备给玩家
     *
     * @param role
     * @param equipSet
     * @param count
     * @param isChoujiang
     */
    public List<RoleEquip> addEquip(Role role, Equip equipSet, int count, boolean isChoujiang) {
        if (count <= 0) {
            return new ArrayList<>();
        }

        List<RoleEquip> list = new ArrayList<>(count);
        for (int i = 0; i < count; i++) {
            short pos = bagService.getPos(role, false);
            RoleEquip roleEquip = getNewcomerEquip(role, pos, equipSet.getPosition());
            /**推送装备信息到客户端*/
            pushEquipInfo(role, roleEquip);

            list.add(roleEquip);
        }

        return list;
    }

    /**
     * 推送装备信息到客户端
     */
    private void pushEquipInfo(Role role, RoleEquip roleEquip) {
        RespIconCartoon respIconCartoon = new RespIconCartoon();
        respIconCartoon.setName(roleEquip.getName());
        respIconCartoon.setRightNow((short) 1);
        respIconCartoon.setParam(roleEquip.getId() + "");
        MessagePusher.pushMessage(role, respIconCartoon);
    }

    /**
     * 减少九曲玲珑笔次数
     */
    public void subShapePenCount(Role role, RoleEquip roleEquip) {
        // 火眼显示气血包需要抓
        FiedValue minValue = roleEquip.getFields().get((short) 1).getField().get((short) 42);
        if (attrService.getValue(minValue.getValue()) <= 1) {
            delRoleEquip(roleEquip, role);
        } else {
            minValue.setValue((int) minValue.getValue() - 1);
            refreshRoleEquip(role, roleEquip);
            role.save();
        }
    }


    /**
     * 直接获取装备最终改造属性
     */
    public LinkedHashMap<Short, RoleEquipField> calcAttribOneKey(short equipLevel, int upgradeLevel, int pos, boolean isPre) {
        LinkedHashMap<Short, RoleEquipField> equipFields = new LinkedHashMap<>();
        Map<String, FiedValue> totalAttrib = new HashMap<>();
        if (isPre) {
            upgradeLevel++;
        }
        for (int level = 1; level <= upgradeLevel; level++) {
            Map<String, FiedValue> resultAttrib = calcAttrib(pos, equipLevel, level);
            resultAttrib.forEach((key, value) -> {
                FiedValue attrib = totalAttrib.get(key);
                if (attrib == null) {
                    totalAttrib.put(key, new FiedValue(value.getType(), value.getValue()));
                } else {
                    attrib.setValue(attrService.getValue(value.getValue()) + attrService.getValue(attrib.getValue()));
                }
            });
        }
        RoleEquipField roleEquipField = new RoleEquipField();
        roleEquipField.setType((short) 2562);
        totalAttrib.values().forEach(value -> roleEquipField.getField().put(value.getType(), value));
        equipFields.put(roleEquipField.getType(), roleEquipField);
        return equipFields;
    }


    /**
     * 获取武器单次的改造属性
     */
    private Map<String, FiedValue> calcAttrib(int equipType, int equipLevel, int rebuildLevel) {
        Map<String, FiedValue> resultAttrib = new HashMap<>();
        if (rebuildLevel > 12 || rebuildLevel <= 0) {
            return resultAttrib;
        }
        if (rebuildLevel > 4) {
            resultAttrib.put("all_attrib", new FiedValue(220, 3));
        }
        if (equipType == Const.WEAPON) {
            resultAttrib.put("phy_power", new FiedValue(3, (int) Math.floor((0.38 * FormulaUtil.getStdAttack(equipLevel + 5)) / 5)));
            resultAttrib.put("mag_power", new FiedValue(10, (int) Math.floor((0.38 * FormulaUtil.getStdAttack(equipLevel + 5)) / 5 * 0.75)));
        } else if (equipType == Const.HELMET || equipType == Const.ARMOR || equipType == Const.BOOT) {
            if (rebuildLevel > 4 && equipLevel >= 100) {
                resultAttrib.put("max_life", new FiedValue(7, (int) Math.floor(FormulaUtil.getStdLife(equipLevel + 5) * 0.0152)));
            }
            resultAttrib.put("def", new FiedValue(8, (int) Math.floor(FormulaUtil.getStdDefense(equipLevel + 5) * 4 / 15)));
        }
        return resultAttrib;
    }

    /**
     * 进化之后修改装备的基础属性 等级
     *
     * @param roleEquip
     * @param evolveEquip
     */
    public void alterEquipFromEvolve(RoleEquip roleEquip, Equip evolveEquip) {
        /**进化成功之后如果刚好进化了10次需要改变装备的Icon*/
        int evolveCount = roleEquip.queryEvolveCount();
        evolveCount++;
        roleEquip.alterEvolveCount(evolveCount);
        if (evolveCount == 10) {
            /**越级了就需要更新Icon和名字*/
            roleEquip.setName(evolveEquip.getKey_name());
            roleEquip.getFields().get((short) 1).getField().get((short) 1).setValue(evolveEquip.getKey_name());
            roleEquip.getFields().get((short) 1).getField().get((short) 40).setValue(evolveEquip.getIcon());
        }
        roleEquip.alterEvolveLevel(roleEquip.queryEvolveLevel() + 1);
        /**然后修改装备的基础属性 和绿色暗属性的最大值属性*/
        NutMap currBasic = attrService.getBasicAttrib(roleEquip.queryEquipPos(false), roleEquip.queryLevel());
        int level = roleEquip.queryLevel() + 10;
        if (level >=179){
            level = 179;
        }
        NutMap nextBasic = attrService.getBasicAttrib(roleEquip.queryEquipPos(false), level);
        Map<Short, Integer> alterBasic = new HashMap<>();
        nextBasic.forEach((key, value) -> {
            int count = roleEquip.queryEvolveCount() % 10;
            int fieldId = attrService.getFiledIdBy(key);
            int nextValue = attrService.getValue(value);
            int currValue = currBasic.getInt(key);
            /**等于0的情况应该是进化了十次 这时候 直接用下个等级的属性就行了*/
            if (count == 0) {
                alterBasic.put((short) fieldId, nextValue);
            } else {
                alterBasic.put((short) fieldId, currValue + (int) Math.floor((nextValue - currValue) / 10) * count);
            }
        });
        // 强化暗属性   2050
        {
            RoleEquipField roleEquipField = roleEquip.getFields().get((short)2050);
            for (Map.Entry<Short, FiedValue> entry:roleEquipField.getField().entrySet()){
                int min = (int) entry.getValue().getValue();
                int max = attrService.getSuitFiledMax(entry.getValue().getType(), evolveEquip.getReq_level(), evolveEquip.getPosition());
                if (max == min){
                    entry.getValue().setValue(max);
                }else {
                    int value = new Random().nextInt(max - min) + min + 1;
                    entry.getValue().setValue(value);
                }
//                logger.error("max==={}==min=={}==level=={}",max,min,evolveEquip.getReq_level());
            }
//            logger.error("roleEquip.getFields()==={}",Json.toJson(roleEquipField));
        }

//        int min = attrService.getSuitFiledMin(fiedValue.getType(), equip.getReq_level(), equip.getPosition());
//        int max = attrService.getSuitFiledMax(fiedValue.getType(), equip.getReq_level(), equip.getPosition());
//        int value = new Random().nextInt(max - min) + min + 1;
//        fiedValue.setValue(value);
        RoleEquipField roleEquipField = new RoleEquipField();
        LinkedHashMap<Short, FiedValue> linkedHashMap = new LinkedHashMap<>();
        roleEquipField.setType((short) 258);
        alterBasic.forEach((fieldId, value) -> linkedHashMap.put(fieldId, new FiedValue(fieldId, value)));
        roleEquipField.setField(linkedHashMap);
        roleEquipField.setField(linkedHashMap);
        roleEquip.getFields().put(roleEquipField.getType(), roleEquipField);

        /**还需要更新改造的  共鸣的属性*/
        LinkedHashMap<Short, RoleEquipField> hashMap = calcAttribOneKey(roleEquip.queryLevel(), roleEquip.queryUpgradeLevel(), roleEquip.queryEquipPos(false), false);
        hashMap.forEach((key, equipField) -> roleEquip.getFields().put(key, equipField));
    }


    /**
     * 改造成功之后添加属性
     */
    public void addUpgradeField(Equip equip, RoleEquip roleEquip) {
        RoleEquipField roleEquipField = roleEquip.getFields().get((short) 6914);
        if (roleEquipField != null && roleEquipField.getField() != null) {
            for (Map.Entry<Short, FiedValue> entry : roleEquipField.getField().entrySet()) {
                setResonanceField(equip, entry, roleEquip.queryUpgradeLevel());
            }
        }
        LinkedHashMap<Short, RoleEquipField> hashMap = calcAttribOneKey(roleEquip.queryLevel(), roleEquip.queryUpgradeLevel(), roleEquip.queryEquipPos(false), false);
        hashMap.forEach((key, equipField) -> roleEquip.getFields().put(key, equipField));
    }


    /**
     * 取贵重物品ID
     */
    public String getValuableItemIdstr(Role role) {
        StringBuilder items = new StringBuilder();
        for (RoleEquip roleEquip : role.getEquipBox().getEquips().values()) {
            if (roleEquip == null || roleEquip.getPosition() < 40 || roleEquip.getPosition() > 201) {
                continue;
            }
            if (roleEquip.isExpensive()) {
                items.append(roleEquip.getPosition()).append("|");
            }
        }
        String str = items.toString();
        if (!Strings.isEmpty(str)) {
            str = str.substring(0, str.length() - 1);
        }
        return str;
    }


    /**
     * 通过便捷使用框使用道具
     */
    public void quickUseItem(Role role, short pos, byte doubleEnabel, byte chongfsEnable) {
        RoleEquip roleEquip = getRoleEquipByPos(role, pos);
        if (roleEquip == null) {
            return;
        }

        String iName = roleEquip.getName();
        /**扣除物品*/
        if (delEquipNum(role, roleEquip, 1) <= 0) {
            return;
        }

        if (iName.equals(Const.QINAG_DAO_LING_SHANG_LING_ITEM_NAME)) {
            int taoRate = 10, martialRate = 20, moneyRate = 3000;
            int needDoublePoint = 4, needChongfsPoint = 4;

            int addTao = taoRate * role.getLevel();
            int addMartial = martialRate * role.getLevel();
            int addMoney = moneyRate * role.getLevel();

            /**双倍*/
            if (doubleEnabel == 1 && pointItemService.subtractDouble(role, needDoublePoint)) {
                addTao *= 2;
                addMoney *= 2;
            }
            /**三倍*/
            if (chongfsEnable == 1 && pointItemService.subtractChongFengSan(role, needChongfsPoint)) {
                addMartial *= 3;
            }

            SpringUtils.getRoleService().addTao(role, addTao);
            SpringUtils.getRoleService().addFightMatiral(role, addMartial);
            SpringUtils.getRoleService().addMoney(role, addMoney);
        }
    }

    /**
     * 获得物品的量词
     */
    public String getItemUnit(String itemName) {
        Medicine medicine = ShopDataPool.getMedicineBy(itemName);
        if (medicine != null) {
            return medicine.getUnit();
        }
        SpecialItem specialItem = mallService.getSpecialItem(itemName);
        if (specialItem != null) {
            return specialItem.getUnit();
        }
        Equip equip = EquipDataPool.getByName(itemName);
        if (equip != null) {
            return equip.getUnit();
        }

        return "个";
    }

    public RespFlyInfo getFlyInfo(List<RoleEquip> roleEquips) {
        RespFlyInfo respFlyInfo = new RespFlyInfo();
        ArrayList<EquipInfo> equipInfos = new ArrayList<>();
        for (RoleEquip roleEquip : roleEquips) {
            if (roleEquip.getPosition() >= 201) {
                continue;
            }
            EquipInfo equipInfo = new EquipInfo();
            equipInfo.setPosition((byte) roleEquip.getPosition());
            equipInfo.setEquipFields(transferList(roleEquip.getFields()), transferList2(roleEquip.getHunQiFields()));
            equipInfos.add(equipInfo);
        }
        respFlyInfo.setList(equipInfos);
        return respFlyInfo;
    }




}

